Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
  1. #21
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    Thanks.

    Well I went through the code again and could not verify that int is automatically converted to an Integer, because:

    Java Code:
    Integer _m = class1.getClass().getModifiers(); //works
    int _m = class1.getClass().getModifiers(); //does not work

  2. #22
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    getModifiers() returns an int, not an Integer. You must be doing something else wrong. "does not work" is not very descriptive.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #23
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    Right.

    Well when it "doesn't work" I see:
    Exception in thread "main" java.lang.Error.: Unresolved compilation problem: Cannot invoke to String() on the primitive int.

    When I use Integer there is no compilation error.

  4. #24
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You don't call toString() on the int, you either use the int directly or use a format.

    Java Code:
    int i = 3;
    System.out.println("int i is " + i);
    System.out.printf("int i is %d%n", i);
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  5. #25
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by OrangeDog View Post
    Or use the toString(int) method as described before.
    Gah!
    What a twit...sorry.
    In my defence it was Friday!
    :)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. [SOLVED] [newbie] java.lang.NullPointerException
    By jon80 in forum New To Java
    Replies: 5
    Last Post: 05-07-2009, 05:19 PM
  2. Regarding default access modifier?
    By makpandian in forum New To Java
    Replies: 2
    Last Post: 03-14-2009, 09:21 AM
  3. Replies: 2
    Last Post: 09-18-2008, 08:30 AM
  4. why we use public access modifier?
    By vichet in forum New To Java
    Replies: 1
    Last Post: 04-04-2008, 08:04 AM
  5. Help with Integer in java
    By susan in forum New To Java
    Replies: 1
    Last Post: 07-14-2007, 06:25 AM

Posting Permissions

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