participate


Generics - Autoboxing with inferred parameter types?
<<   Back to Forum  |   Give us Feedback
This topic has 3 replies on 1 page.
rreyelts
Posts:568
Registered: 11/12/97
Autoboxing with inferred parameter types?   
Sep 3, 2003 12:44 PM

 
Shouldn't autoboxing work with inferred parameter types?

For example, I have:
class Pair<T,U> {
  public <T,U> static Pair<T,U> make( T t, U u ) {
    return new Pair( t, u );
  }
  Pair( T t, U u ) {
    first = t;
    second = u;
  }
  private T first;
  private U second;
}
and when I try:
Pair.make( "Hello", 500 );
I'm told that the inferred arguments, java.lang.String and int do not conform to the bounds of the type variables. I'd like autoboxing/inference to work together to "do the right thing" here.

God bless,
-Toby Reyelts
 
fredastaire
Posts:97
Registered: 1/3/00
Re: Autoboxing with inferred parameter types?   
Sep 3, 2003 6:45 PM (reply 1 of 3)  (In reply to original post )

 
Does
Pair.<String,Integer>make( "Hello", 500);

work?
 
rreyelts
Posts:568
Registered: 11/12/97
Re: Autoboxing with inferred parameter types?   
Sep 4, 2003 8:04 AM (reply 2 of 3)  (In reply to #1 )

 
That works fine, but I don't understand your point. I'm asking for autoboxing to work with inferred type parameters. You're explicitly specifying them.

God bless,
-Toby Reyelts
 
fredastaire
Posts:97
Registered: 1/3/00
Re: Autoboxing with inferred parameter types?   
Sep 4, 2003 2:06 PM (reply 3 of 3)  (In reply to #2 )

 
No, I agree that inference should work. (And I've added this to the list of bugs at http://cscott.net/Projects/GJ#bugs ). I was just curious whether autoboxing would work given the correct results of inference. It seems it does. So it really is only an inference problem.
 
This topic has 3 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 56
  • Guests : 127

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums