harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hari ks <hari_...@yahoo.com>
Subject Re: strong type cast needed in java. (overriding enhancement.)
Date Thu, 23 Dec 2010 14:06:27 GMT
c++:
    base *b=new base;
    sub *s=new sub;
    s ->base::foo();  // private instance variable of base has 0 or unknown 
value while executing foo() method of base class..

can't this be extended so as pass base class variable along with method call?
may be something like
s -> base{i=20,j=11}::foo();// here i and j were private variables of base..

this concept could be implemented in java.

thanks & rgds,
Hari




________________________________
From: hari ks <hari_tcs@yahoo.com>
To: dev@harmony.apache.org
Sent: Thu, December 23, 2010 6:06:46 PM
Subject: Re: strong type cast needed in java. (overriding enhancement.)

hi ,

c++ allows more combinations between instructions(functions) and data(variables) 

than java.
eg in c++:
base* b;
sub* s;  // sub extends base and both have method foo()..
b -> foo(); // will call base foo()
s -> foo(); // will call sub foo()
s ->base::foo(); // will call base foo()

java didn't add this mostly -because functions in super class might access 
'private members' of super class  which there is no way populating in subclass 
object and throw Null Exception..
Yet again - if these specific functions in superclass that could be accessed 
from subclass were compile time checked as not to access any private variable of 

super class, this feature may add meaning.

There could be more better design than just preventing subclass not to access 
super class methods..

thanks & rgds,
Hari 



________________________________
From: "Jimmy,Jing Lv" <firepure@gmail.com>
To: dev@harmony.apache.org
Sent: Thu, December 23, 2010 3:34:51 PM
Subject: Re: strong type cast needed in java. (overriding enhancement.)

Hi Hari,

      I see there is no such mechanism for Java now. I suppose it may be due
to java single inheritance and dynamic bonding.
     Technically strong type casting is possible with bytecode instruction
or something, however I'd rather design it clear to avoid such invoking -
say, if you want A.foo(), create A a = new A(), or avoid overriding foo() in
B. It sounds a syntax problem to invoke a parent method in a child class
instance while the method is already overrode.  It may have some problem
with strong type casting. For an example, if you have a public basic type A,
which has an implemented method foo(), and then create some internal
implementation B, C, which C extends B and both of them override foo(). With
a factory of A you can get an object "a" which is really C instances, then
it will be hard to tell what can be invoked for a.super.foo()?

     Sorry I don't catch you that what is the benefit do you think for
strong type casting on Java?

2010/12/23 hari ks <hari_tcs@yahoo.com>

> I have put up a post here :
>
>http://programparadigm.blogspot.com/2010/12/method-overriding-enhancements-strong.html
>
>l
>
>
> Suppose class B extends A.
> A a = new B();
> ((A)a).foo(); // still calls class B's foo() method.
>
> Can something like "a.super.foo();" method invocation be made possible. Or
> ((A
> strong)a).foo();  should call A's foo() method with B's instance data.
>
> similar thing for C++.
>
> Is there a way to already do this?
>
> thanks & regards,
> Hari
>
>
>
>




-- 

Best Regards!

Jimmy, Jing Lv


      
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message