widening and boxing - why isn't it allowed?

Discussion in 'Java' started by mluebeck, Jan 8, 2007.

  1. mluebeck

    mluebeck Guest

    Hi everyone,

    I'm trying to do widening and then boxing, but it's impossible. Can
    anyone tell me the reason?
    Why is that behaviour useful?

    class WB {
    static void go(Integer x) { System.out.println("Integer"); }
    public static void main(String [] args) {
    short s = 5;
    go(s); // must widen then box - illegal. But why??
    }
    }

    thanks for your answers!

    Mario
    mluebeck, Jan 8, 2007
    #1
    1. Advertising

  2. mluebeck

    Hemal Pandya Guest

    mluebeck wrote:
    > Hi everyone,
    >
    > I'm trying to do widening and then boxing, but it's impossible. Can
    > anyone tell me the reason?
    > Why is that behaviour useful?


    JLS 5.3 (Method Invocation Conversion) mentions that Method invocation
    contexts allow the use of one of identity, widening primitive or
    reference, boxing and unboxing conversion. Though it does not
    specifically say so, this implies that more then one conversion is not
    allowed.

    No rationale is provided, but I assume it is to not further complicate
    the already complex overload resolution rules.

    >
    > class WB {
    > static void go(Integer x) { System.out.println("Integer"); }
    > public static void main(String [] args) {
    > short s = 5;
    > go(s); // must widen then box - illegal. But why??
    > }
    > }
    >
    > thanks for your answers!
    >
    > Mario
    Hemal Pandya, Jan 9, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siz
    Replies:
    1
    Views:
    504
    Catherine Lowery
    Dec 12, 2004
  2. =?Utf-8?B?RWR3YXJkIFNtaXQ=?=
    Replies:
    1
    Views:
    306
    =?Utf-8?B?RWR3YXJkIFNtaXQ=?=
    May 21, 2004
  3. jeffc
    Replies:
    4
    Views:
    2,709
    jeffc
    Dec 9, 2004
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,660
    Smokey Grindel
    Dec 2, 2006
  5. Iñaki Baz Castillo
    Replies:
    13
    Views:
    466
    Iñaki Baz Castillo
    May 1, 2011
Loading...

Share This Page