Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > diamond operator

Reply
Thread Tools

diamond operator

 
 
Roedy Green
Guest
Posts: n/a
 
      04-04-2012
I was looking over the table of contents of a book about new features
in Java 7 and came across a reference to the "diamond operator".

It turns out to be simple, but one of the precious bits of Java
syntactic sugar to make it terser.

http://fahdshariff.blogspot.ca/2011/...-operator.html

http://mindprod.com/book/9781849685627.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
When you were a child, if you did your own experiment
to see if it was better to put to cocoa into your cup first
or the hot milk first, then you likely have the programmer gene..
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      04-04-2012
On 4/3/2012 9:54 PM, Roedy Green wrote:
> I was looking over the table of contents of a book about new features
> in Java 7 and came across a reference to the "diamond operator".
>
> It turns out to be simple, but one of the precious bits of Java
> syntactic sugar to make it terser.
>
> http://fahdshariff.blogspot.ca/2011/...-operator.html


It is listed in the release notes:
http://www.oracle.com/technetwork/ja...es-418459.html
that link to the docs:

http://docs.oracle.com/javase/7/docs...-creation.html

It was probably also discussed here last summer when
Java 7 was released.

Arne
 
Reply With Quote
 
 
 
 
Silvio Bierman
Guest
Posts: n/a
 
      04-04-2012
On 04/04/2012 03:54 AM, Roedy Green wrote:
> I was looking over the table of contents of a book about new features
> in Java 7 and came across a reference to the "diamond operator".
>
> It turns out to be simple, but one of the precious bits of Java
> syntactic sugar to make it terser.
>
> http://fahdshariff.blogspot.ca/2011/...-operator.html
>
> http://mindprod.com/book/9781849685627.html


With some exaggeration one might call it Java's type inferencing...
 
Reply With Quote
 
David Lamb
Guest
Posts: n/a
 
      04-04-2012
On 04/04/2012 7:12 AM, Silvio Bierman wrote:
> On 04/04/2012 03:54 AM, Roedy Green wrote:
>> I was looking over the table of contents of a book about new features
>> in Java 7 and came across a reference to the "diamond operator".

> With some exaggeration one might call it Java's type inferencing...


Well, maybe, but from the little I recall of my programming language
design classes, "real" type inferencing is a lot more powerful, so I
think you ought to have said "much exaggeration."
 
Reply With Quote
 
Silvio Bierman
Guest
Posts: n/a
 
      04-04-2012
On 04/04/2012 02:23 PM, David Lamb wrote:
> On 04/04/2012 7:12 AM, Silvio Bierman wrote:
>> On 04/04/2012 03:54 AM, Roedy Green wrote:
>>> I was looking over the table of contents of a book about new features
>>> in Java 7 and came across a reference to the "diamond operator".

>> With some exaggeration one might call it Java's type inferencing...

>
> Well, maybe, but from the little I recall of my programming language
> design classes, "real" type inferencing is a lot more powerful, so I
> think you ought to have said "much exaggeration."


Yep, it was an understatement.
 
Reply With Quote
 
Jim Janney
Guest
Posts: n/a
 
      04-04-2012
Roedy Green <> writes:

> I was looking over the table of contents of a book about new features
> in Java 7 and came across a reference to the "diamond operator".
>
> It turns out to be simple, but one of the precious bits of Java
> syntactic sugar to make it terser.
>
> http://fahdshariff.blogspot.ca/2011/...-operator.html
>
> http://mindprod.com/book/9781849685627.html


This isn't wrong, but it fixes a problem I never knew I had. Any
competent IDE will expand that for you anyway.

--
Jim Janney

 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      04-04-2012
On 4/4/2012 8:23 AM, David Lamb wrote:
> On 04/04/2012 7:12 AM, Silvio Bierman wrote:
>> On 04/04/2012 03:54 AM, Roedy Green wrote:
>>> I was looking over the table of contents of a book about new features
>>> in Java 7 and came across a reference to the "diamond operator".

>> With some exaggeration one might call it Java's type inferencing...

>
> Well, maybe, but from the little I recall of my programming language
> design classes, "real" type inferencing is a lot more powerful, so I
> think you ought to have said "much exaggeration."


Give that the JLS says:

<quote>
If the type argument list to the class is empty — the diamond form "<>"
— the type arguments of the class are inferred.
</quote>

then the usage of "type inference" can be defended.

But it is certainly not what type inference is in languages
like Scala etc..

Arne

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      04-05-2012
Jim Janney wrote:
> Roedy Green writes:
>> I was looking over the table of contents of a book about new features
>> in Java 7 and came across a reference to the "diamond operator".
>>
>> It turns out to be simple, but one of the precious bits of Java
>> syntactic sugar to make it terser.
>>
>> http://fahdshariff.blogspot.ca/2011/...-operator.html
>>
>> http://mindprod.com/book/9781849685627.html

>
> This isn't wrong, but it fixes a problem I never knew I had. Any
> competent IDE will expand that for you anyway.


It was added to Java to satisfy the whiners who were afraid they might strain a finger typing "Ctrl-V" or hitting ENTER on the IDE suggestion. Heaven help any of those folks should they ever have to actually work for a living..

Not that I eschew the diamond operator myself now that it's here, but I wasn't clamoring for it beforehand.

--
Lew
Diamonds are a girl's best friend. Dogs are a man's best friend. Diamonds cost more at first, but don't require feeding, walking, shots, neutering or spaying, veterinary or funeral bills, housebreaking, orreplacement expensesfor broken goods, and don't have litters. Still, I wish I had a dog.
 
Reply With Quote
 
Arivald
Guest
Posts: n/a
 
      04-05-2012
W dniu 2012-04-04 03:54, Roedy Green pisze:
> I was looking over the table of contents of a book about new features
> in Java 7 and came across a reference to the "diamond operator".
>
> It turns out to be simple, but one of the precious bits of Java
> syntactic sugar to make it terser.
>
> http://fahdshariff.blogspot.ca/2011/...-operator.html
>
> http://mindprod.com/book/9781849685627.html


It will be better to provide "auto" type detector, like in C++.
For example, instead of:
Map<Integer, List<String>> map = new HashMap<Integer, List<String>>();
use:
auto map = new HashMap<Integer, List<String>>();

....and "map" variable will be resolved at compile time to
HashMap<Integer, List<String>>.

This allow very handy construct, like:

auto data = SomeService.getProviders();

In this case type of "data" will be deducted from return type of
SomeService.getProviders().

This will save lot of typing. And save refactoring time in case if
getProviders return type changes. And will auto-adapt to changes in
libraries.

--
Arivald
 
Reply With Quote
 
David Lamb
Guest
Posts: n/a
 
      04-05-2012
On 04/04/2012 7:41 PM, Arne Vajhøj wrote:
> But it is certainly not what type inference is in languages
> like Scala etc..

Let alone Standard ML, where IIRC type inference is NP-hard.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Odd behavior of operator=() in diamond inheritance situation Juha Nieminen C++ 1 03-02-2009 12:00 PM
translate Perl diamond operator to Ruby Chad Perrin Ruby 11 04-16-2007 07:03 PM
MSI P4N Diamond NF4-SLI Intel Edition Motherboard Review Silverstrand Front Page News 0 09-14-2005 08:48 PM
<> the Diamond Operator maryellen sniffen Perl Misc 3 12-31-2004 02:19 PM
binmode and the diamond operator J. Romano Perl Misc 6 11-17-2003 02:47 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57