File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Forbidden Conversions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Forbidden Conversions" Watch "Forbidden Conversions" New topic
Author

Forbidden Conversions

Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Hi,
This is an abstract from JLS:

5.1.7 Forbidden Conversions
  • There is no permitted conversion from any reference type to any primitive type.
  • Except for the string conversions, there is no permitted conversion from any primitive type to any reference type.
  • There is no permitted conversion from the null type to any primitive type.
  • There is no permitted conversion to the null type other than the identity conversion.
  • There is no permitted conversion to the type boolean other than the identity conversion.
  • There is no permitted conversion from the type boolean other than the identity conversion and string conversion.
  • There is no permitted conversion other than string conversion from class type S to a different class type T if S is not a subclass of T and T is not a subclass of S.
  • There is no permitted conversion from class type S to interface type K if S is final and does not implement K.
  • There is no permitted conversion from class type S to any array type if S is not Object.
  • There is no permitted conversion other than string conversion from interface type J to class type T if T is final and does not implement J.
  • There is no permitted conversion from interface type J to interface type K if J and K declare methods with the same signature but different return types.
  • There is no permitted conversion from any array type to any class type other than Object or String.
  • There is no permitted conversion from any array type to any interface type, except to the interface type Cloneable, which is implemented by all arrays.
  • There is no permitted conversion from array type SC[] to array type TC[] if there is no permitted conversion other than a string conversion from SC to TC.



  • I dont understand the points in bold.
    also i am not able to practically implement:
    "conversion from any array type to Object or String. "

    Please Help
    Thanx

    Sandy


    Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
    Barry Gaunt
    Ranch Hand

    Joined: Aug 03, 2002
    Posts: 7729
    Which JLS is this? The second or third edition?


    Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
    Getting someone to think and try something out is much more useful than just telling them the answer.
    Barry Gaunt
    Ranch Hand

    Joined: Aug 03, 2002
    Posts: 7729
    The third edition says in section 5.1.12 Forbidden Conversions:
    Any conversion not explicity allowed is forbidden.


    That's it !

    So it looks as if you have JLS 2nd edition. In that "boxing" did not exist in Java, so you could not convert between primitives and their wrapper classes. In Java 5.0 you can. For instance an int can be converted to an Integer, and vice versa. Or a boolean can be converted to a Boolean or vice versa.
    [ September 16, 2005: Message edited by: Barry Gaunt ]
    Barry Gaunt
    Ranch Hand

    Joined: Aug 03, 2002
    Posts: 7729
    This code:


    Shows an array being converted to an Object (in method m1) and to a String (in the concatenation operation.)

    Compiled with Java 5.0.
    Sandeep Chhabra
    Ranch Hand

    Joined: Aug 28, 2005
    Posts: 340
    Thanx Barry.

    Got your point.

    Sandy
    Mark Spritzler
    ranger
    Sheriff

    Joined: Feb 05, 2001
    Posts: 17249
        
        6

    It is forbidden, like the passion between two people from different sides of the train tracks.

    It sounds so tropical, Forbibben Conversions. I think my wife has that steamy romance novel with the same title.

    Mark


    Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
    How to Ask Questions the Smart Way FAQ
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Forbidden Conversions
     
    Similar Threads
    arrays
    Conversion from byte[] -> int[]
    my notes on JLS for any1 who needs them !!
    how to create a null type
    null as arg in mehods