Re: No Equals on interfaces
From: Michi Henning (michi_at_zeroc.com)
Date: 09/06/04
- Next message: Michi Henning: "Re: No Equals on interfaces"
- Previous message: Michi Henning: "Re: No Equals on interfaces"
- In reply to: Herfried K. Wagner [MVP]: "Re: No Equals on interfaces"
- Next in thread: Herfried K. Wagner [MVP]: "Re: No Equals on interfaces"
- Reply: Herfried K. Wagner [MVP]: "Re: No Equals on interfaces"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 06 Sep 2004 11:02:37 +1000 To: "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at>
Herfried K. Wagner [MVP] wrote:
> * Michi Henning <michi@zeroc.com> scripsit:
>
>>the following code won't compile, but I believe it should:
>>
>>Interface X
>>End Interface
>>
>>Module M
>> Sub Main(ByVal args As String())
>> Dim iref As X
>> iref.Equals(iref) ' 'Equals' is not a member of 'vb.I'.
>> End Sub
>>End Module
>>
>>The compiler complains that X does not have a member Equals.
>>(The same complaint is issued for the other methods of System.Object:
>>GetHashCode, GetType, and ToString.)
>>
>>This seems wrong, given that C# compiles the equivalent code
>>without complaint.
>
>
> That's simply different behavior in C# and VB.NET, and I think that the
> behavior shown by VB.NET is more correct. Interfaces in .NET do /not/
> have a base type if they don't inherit from another interface.
Nonsense. From the C# language specification for predefined types:
object: The ultimate base type of all other types
> In C#, the compiler doesn't complain for some reason, but the code you
> listed above is rather useless because it will throw a
> 'NullReferenceException'.
Oh, *please*. The point is that the expression iref.Equals(iref) will not
compile, not what happens at run time.
> None of the methods you can access from C#
> are useful because they are all instance members and interfaces cannot
> be instantiated.
Again, nonsense. I can pass a reference to a class that is derived from I
to another method. Are you *really* suggesting that this method then should
not be allowed to invoke Equals on the reference?
Moreover, you ignored the following:
>>Also, the following works fine:
>>
>>Dim iref As X
>>Dim oref As Object = iref
>>oref.Equals(oref)
>>
>>Clearly, if there is an implicit conversion from X to Object,
>>then X must have the members of Object (otherwise, implicit
>>conversion would have to be illegal.)
According to what you say, the implicit conversion to object (which
is allowed by the compiler) would then lead to me holding a reference
that allows me to call Equals on it, yet does not support the Equals
method. Again, that's simply nonsense. *All* reference types are derived
from object. Whether the formal type of a references is for an interface
or to a class is irrelevant. The VB compiler is simply broken in this
respect, period.
>>Does anyone know whether this problem is fixed for Whidbey?
>
>
> There is no problem in VB.NET. It's IMO a C# problem.
Please read the language specification. This isn't a C# problem,
it's a bug in VB.
Cheers,
Michi.
- Next message: Michi Henning: "Re: No Equals on interfaces"
- Previous message: Michi Henning: "Re: No Equals on interfaces"
- In reply to: Herfried K. Wagner [MVP]: "Re: No Equals on interfaces"
- Next in thread: Herfried K. Wagner [MVP]: "Re: No Equals on interfaces"
- Reply: Herfried K. Wagner [MVP]: "Re: No Equals on interfaces"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|