Assigning Interface to Object

Steven Schveighoffer schveiguy at yahoo.com
Sat Jan 15 09:44:05 PST 2011


On Sat, 15 Jan 2011 11:34:05 -0500, Simen kjaeraas  
<simen.kjaras at gmail.com> wrote:

> Mandeep Singh Brar <mandeep at brars.co.in> wrote:
>
>> Hi,
>>
>> I am not able to assign an interface to object. The following code
>> does not compile.
>>
>> module testObj;
>>
>> public interface testInterface {
>> 	void someMethod();
>> }
>> public class testObj
>> {
>> 	Object someCaller;
>> 	this(Object caller) {
>> 		someCaller = caller;
>> 	}
>> 	this(testInterface tI, bool xyz) {
>> 		someCaller = tI;
>> 	}
>> }
>>
>> Shouldn't this work?
>
> Nope. D allows interfaces to be special in certain cases (notably COM,
> though other may be added in the future), and this precludes making
> interfaces implicitly castable to Object.

Which unnecessarily complicates things.  For example, you can't compare  
two interfaces (try it!).

Sorry, had to get my dig in there :P

-Steve


More information about the Digitalmars-d-learn mailing list