Results 1 to 2 of 2

Thread: Casting issues...

  1. #1

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    Angry Casting issues...

    why does the following line of code give me a compile error?:

    Code:
    Long l =  (Class.forName("java.lang.Long")) ((Object) ( new Long (123)));
    shouldn't this guarantee that the objecty passed to the variable will be cast down into a "Long"?
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Class.forName() returns an instance of the class you pass in. Its a method, not an operator. For casting, you just do it the way you casted the Long to an Object.
    Code:
    Long l =  (Long)((Object) (new Long (123)));
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width