Re: [Ikvm-developers] The type of a boxed primitive
Brought to you by:
jfrijters
From: Stephen S. <ste...@ho...> - 2004-06-11 11:46:53
|
> When a .NET boxed int (i.e. not a java.lang.Integer) is encountered by > Java code and it calls getClass() on the object, the Class that is > returned is Integer.TYPE (the Class corresponding to the Java primitive > int). For concreteness, I'm thinking of the following Java code: void foo(Object obj) { if (obj instanceof Integer) { Integer i = (Integer) obj; ... } } If this method is called with a .NET boxed int parameter, will the instanceof method return true? In other words, is Integer.TYPE a supertype of the java.lang.Integer class? Stephen ----- Original Message ----- From: "Jeroen Frijters" <je...@su...> To: <ikv...@li...> Sent: Wednesday, June 09, 2004 7:50 AM Subject: [Ikvm-developers] The type of a boxed primitive Hello everyone, When a .NET boxed int (i.e. not a java.lang.Integer) is encountered by Java code and it calls getClass() on the object, the Class that is returned is Integer.TYPE (the Class corresponding to the Java primitive int). This makes sense, but I didn't consciously design it like this. It's just a natural consequence of how primitive types are handled in reflection. I only recently discovered this issue and now I'm wondering whether I should keep the current behaviour, or change it. Pro current behaviour: - It already works. - It makes sense. Cons: - If Java will ever support real boxing, this approach forces Java boxes to use .NET boxes (this would probably be desirable anyway, but not if it is too expensive [in terms of performance]). - Potentially confuses Java code, that never expects to see instances of Integer.TYPE (and friends). - It could cause complications if .NET is ever going to support strongly typed references to boxes. I'm leaning towards keeping the current behaviour, mostly because the cons all seem pretty unlikely. Any thoughts on this issue? Regards, Jeroen ------------------------------------------------------- This SF.Net email is sponsored by: GNOME Foundation Hackers Unite! GUADEC: The world's #1 Open Source Desktop Event. GNOME Users and Developers European Conference, 28-30th June in Norway http://2004/guadec.org _______________________________________________ Ikvm-developers mailing list Ikv...@li... https://lists.sourceforge.net/lists/listinfo/ikvm-developers |