June 09, 2004
In article <c9b5e1$mho$1@digitaldaemon.com>, Andy Friesen says...
>
>Ant wrote:
>
>> "this" should represent the object not something else.
>> on the line "0,typeof(this).a();", "this" clearly does not represent the
>> object.
>
>It's perfectly consistent: 'this' is the object.  typeof(this) is whatever type it happens to be cast as at the moment.

I don't want to restart this discussion, I cleary lost it
I just want to show here I was comming from:

I checked on java a couple days ago and
this is what I expect from "this":
(of course I shouldn't bring expectation from other languages)

<java>
class A
{
String whoAmI()
{
// the keyword "this" is redundant here
return this.getClass().getName();
}
}

public class AB extends A
{
public static void main(String [] args)
{
A a = new AB();
System.out.println("I am "+a.whoAmI());
}
}
</java>
<console>
C:\j2sdk1.4.2_04\bin>javac AB.java

C:\j2sdk1.4.2_04\bin>java AB
I am AB

</console>

So I insist that D is now "sometimes polymorphic"
or "not garantied to be polymorphic".
Virtual functions are not garantied to be called through the virtual
table even if the access modifier seems to indicate that.

the example (similar) posted on this subject is a good one:

class A
{

public int get()
{
return 14;
}

public int[] multiGet()
{
int[] ii;
ii ~= typeof(this).get(); // bad, bad...
ii ~= typeof(this).get(); // bad, bad...
}
}

class B : A
{
int numberOfGets = 0;
public int get()
{
// you whish! this is not garantied to work on D
// but there is nothing on the API of class A that
// denotes that!
++numberOfGets;
return super.get();
}
}

well, if I want a perfect language I'll have to write it.

Ant


June 09, 2004
Ant wrote:

> I don't want to restart this discussion, I cleary lost it
> I just want to show here I was comming from:
> 
> I insist that D is now "sometimes polymorphic"
> or "not garantied to be polymorphic".
> Virtual functions are not garantied to be called through the virtual
> table even if the access modifier seems to indicate that.

aha.  I see.  This does have the potential to break invariants.

It is (or it should be) intended to be a last resort.  Ideally, the programmer would just make the method in question final, thereby evading this whole mess.

 -- andy
1 2
Next ›   Last »