[2353] in java-interest
Re: casting
daemon@ATHENA.MIT.EDU (Thomas Ball)
Fri Sep 29 17:52:55 1995
Date: Fri, 29 Sep 1995 12:32:19 -0700
From: Thomas.Ball@Eng.Sun.COM (Thomas Ball)
To: lemay@lne.com
Cc: java-interest@java.Eng.Sun.COM
> I've managed to explicitly cast between objects of my own making with
> no problem. I've managed to cast ints to floats and between other
> base types.
>
> My next plan was simply to cast an int to its "wrapper" equivalent:
>
> Integer t = (Integer) 5;
>
> Nope. Compiler error. Invalid cast.
>
>
> Am I right in coming to the conclusion that one has to use new Integer(5)
> to get an Integer object, instead of casting? Does that imply you
> can't cast between the base types and objects at all?
Absolutely right -- we explicitly ban casting base types to objects for
security reasons. In Java you can't forge objects, the way you can in
other languages such as C++. It makes my life as the debugger writer
harder, but everyone else's safer.
Tom
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com