posted 20 years ago
throws a NullPointerException - nothing wront with that, but the way I figure, 'i' has the type Integer even if it's value is null. When calling 'func' 'value' gets the type Integer, even if the value is null - is this a correct assumption? If 'i' was not null, clazz would of course be 'java.lang.Integer'
Welcome to JavaRanch S�ren. You must remember that 'i' is not an object but a mere reference to that object. It's class would actually be java.lang.Reference if I am not mistaken. So when you call 'i.getClass()', 'i' is derefernced and now the runtime is attempting to access the underlying object and if that points to an invalid heap address, then naturally a NPE is going to be thrown.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher