superclass - Why is super.super.method(); not allowed in Java? -


i read this question , thought solved (not isn't solvable without) if 1 write:

@override public string tostring() {     return super.super.tostring(); } 

i'm not sure if useful in many cases, wonder why isn't , if exists in other languages.

what guys think?

edit: clarify: yes know, that's impossible in java , don't miss it. nothing expected work , surprised getting compiler error. had idea , discuss it.

it violates encapsulation. shouldn't able bypass parent class's behaviour. makes sense able bypass own class's behaviour (particularly within same method) not parent's. example, suppose have base "collection of items", subclass representing "a collection of red items" , subclass of representing "a collection of big red items". makes sense have:

public class items {     public void add(item item) { ... } }  public class reditems extends items {     @override     public void add(item item)     {         if (!item.isred())         {             throw new notreditemexception();         }         super.add(item);     } }  public class bigreditems extends reditems {     @override     public void add(item item)     {         if (!item.isbig())         {             throw new notbigitemexception();         }         super.add(item);     } } 

that's fine - reditems can confident items contains red. suppose were able call super.super.add():

public class naughtyitems extends reditems {     @override     public void add(item item)     {         // don't care if it's red or not. take that, reditems!         super.super.add(item);     } } 

now add whatever like, , invariant in reditems broken.

does make sense?


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -