participate


Generics - adding generics 2.0 is available
<<   Back to Forum  |   Give us Feedback
This topic has 34 replies on 3 pages.    1 | 2 | 3 | Next »
jtr
Posts:45
Registered: 5/30/97
adding generics 2.0 is available   
May 28, 2003 6:29 PM

 
http://developer.java.sun.com/developer/earlyAccess/adding_generics/index.html

Including:
variance whitepaper
JSR 201 features

Can't wait to try it...
 
schapel
Posts:2,586
Registered: 6/22/99
Re: adding generics 2.0 is available   
May 28, 2003 9:51 PM (reply 1 of 34)  (In reply to original post )

 
When I try to open the PDFs with Adobe Acrobat Reader 4.05b on Windows 98, I get errors about it not being able to extract the embedded font. Is Acrobat Reader 5 required to open the PDFs?
 
lomov
Posts:1
Registered: 11/10/98
Re: adding generics 2.0 is available   
May 29, 2003 1:11 AM (reply 2 of 34)  (In reply to original post )

 
What about specification update?
http://jcp.org/aboutJava/communityprocess/review/jsr014/index.html
still downloads version 0.1 (without new syntax for method calls etc.)

TIA,
Friendly
Dmitry
 
schapel
Posts:2,586
Registered: 6/22/99
Re: adding generics 2.0 is available   
May 29, 2003 1:52 AM (reply 3 of 34)  (In reply to #1 )

 
I was able to open the PDFs with Ghostscript. After reading the variance whitepaper, the idea seems so simple and elegant that I don't know why it wasn't obvious to me before. I expect, however, to see posts about how complicated it is and how it'll ruin Java. I'll have to write some variance code to see how it works in practice... maybe there's a complexity that I'm not seeing yet.
 
mthornton
Posts:305
Registered: 7/7/97
Re: adding generics 2.0 is available   
May 29, 2003 3:27 AM (reply 4 of 34)  (In reply to #3 )

 
Acrobat Reader 5 does work. The variance proposal looks very interesting and elegant. However the luddite tendency are sure to be horrified. I'm sure that Microsoft will also be looking at it with interest.
 
fredastaire
Posts:97
Registered: 1/3/00
Re: adding generics 2.0 is available   
May 29, 2003 9:20 AM (reply 5 of 34)  (In reply to #4 )

 
For more information, be sure to see Igarashi and Viroli's paper on variance, which is behind this whole thing:
http://www.sato.kuis.kyoto-u.ac.jp/~igarashi/papers/variance.html

This explains better the exact mechanics of the type system.
 
rreyelts
Posts:568
Registered: 11/12/97
Re: adding generics 2.0 is available   
May 29, 2003 12:17 PM (reply 6 of 34)  (In reply to original post )

 
I'm pretty excited about this, though I have a few small reservations.

For example, I find it irritating that invariance is the default for generic types, but not the default for arrays. People won't want to use invariant arrays, because the "dynamic arrays" are "more-powerful" and don't require as much typing, as silly as that sounds. I can only hope that since you can't use dynamic arrays with generic types that people will be forced into using safe arrays. Perhaps it would have been better to default to safe-arrays, but have a "backwards-compatible" compiler mode where programs would still compile if you were treating an array as "dynamic", but you'd get "severe compiler warnings".

The syntax also seems a little weird to me, and I believe it is likely to throw off people new to the language. As crazy as it sounds, I'd almost welcome some new keywords over +, -, and = being "overloaded" the way they are.

Otherwise, kudos to Sun and the generics team for this cool new feature. This is where I want to see Java headed - a more typesafe, more powerful language.

God bless,
-Toby Reyelts
 
immute
Posts:1
Registered: 3/10/03
Re: adding generics 2.0 is available   
May 29, 2003 1:37 PM (reply 7 of 34)  (In reply to original post )

 
The variance annotations are absolutely excellent, and in my opinion Java has needed this for a long time. I really hope this stuff makes it into the release, as it will be a true joy to work with!
 
spf1
Posts:7
Registered: 6/12/98
Re: adding generics 2.0 is available   
May 29, 2003 1:56 PM (reply 8 of 34)  (In reply to original post )

 
Variance is very nice, please keep it!
 
jtr
Posts:45
Registered: 5/30/97
Re: adding generics 2.0 is available   
May 29, 2003 6:48 PM (reply 9 of 34)  (In reply to original post )

 

Having looked at it for only a couple hours... it looks neat and makes
the type system "feel" better. However, thinking about variance is
something I just don't do now (well, except for wanting coveriant return
types).

I wonder: will the average Java developer want to think much about if
their types should be coveriant, contravariant, etc...? Eventually it will
become second nature, but until then I expect resistance.
 
gafter
Posts:669
Registered: 6/25/98
Re: adding generics 2.0 is available   
May 29, 2003 11:06 PM (reply 10 of 34)  (In reply to original post )

 
For those of you who want to vote for it,
the variance type system is 4856545 in the bug database.
 
mthornton
Posts:305
Registered: 7/7/97
Re: adding generics 2.0 is available   
May 30, 2003 1:44 AM (reply 11 of 34)  (In reply to #10 )

 
It now has all three of my votes.
 
borganism
Posts:3
Registered: 11/24/02
Re: adding generics 2.0 is available   
May 30, 2003 3:35 AM (reply 12 of 34)  (In reply to #11 )

 
Variance is looking very good indeed.

Can anyone explain what the difference is between List<-String> and List<Object> ?

And is there a place where I can vote for making invariance the default for arrays?
 
jonathanfinn
Posts:53
Registered: 6/30/97
Re: adding generics 2.0 is available   
May 30, 2003 7:18 AM (reply 13 of 34)  (In reply to #12 )

 
Judging from the code example in the generics 2.0 download, variable argument lists aren't as elegant as I was expecting. Here's the example:

<code>
// varargs
public static void printf(String fmt, Object[] args...) {
int i = 0;
// foreach on primitive array
for (char c : fmt.toCharArray()) {
if (c == '%')
System.out.print(args[i++]);
else
System.out.print(c);
}
}

...

printf("Addition: % plus % equals %\n", 1, 1, 2);
...
</code>


It looks like you add '...' at the end of a method's parameter list, to show where several parameters can be packed into an array. I thought they were going for a more elegant solution which could be used anywhere, not just in method calls, so you do something like this:

Object[] list = {1,2.3,"hello"};

i.e. the syntax {1,2.3,"hello"} just creates an Object array and dumps the values in it. So you could use it in place of any method parameter of type Object[], and in other places too. No need for a method to 'expect' a variable parameter list.

The new '...' solution seems kludgy, but maybe it was forced on them by this new variance feature. And/or maybe it was the only way to indicate that you want to put your parameters into a specific array like Number[] instead of Object[]?

Any ideas?
 
spf1
Posts:7
Registered: 6/12/98
Re: adding generics 2.0 is available   
May 30, 2003 7:37 AM (reply 14 of 34)  (In reply to #13 )

 
I think the method included is more general. You can still do almost what you want with static imports:

Object [] array = ar(1,2,3,"Hello");

and the fact that this works through a user defined method lets you do things like

Integer [] array = intArray(1,2,3,4,5,6);

which you could not do with concise array literals.
 
This topic has 34 replies on 3 pages.    1 | 2 | 3 | Next »
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 : 25
  • Guests : 129

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