| Author |
Valid code, but what does it mean?
|
Luigi Plinge
Ranch Hand
Joined: Jan 06, 2011
Posts: 441
|
|
bset is initialized but aset isn't - is it interpreted as something in generics?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
It means that aset is a HashSet<Character> variable which isn't initialized, and bset is a HashSet<Character> variable which is initialized to refer to a HashSet<Character> object. It's nothing to do with generics; consider this:
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
It is exactly the same as this:
I wouldn't use such a notation to declare variables in one line and initialize only one of them, because it's confusing.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Jesper de Jong wrote:I wouldn't use such a notation to declare variables in one line and initialize only one of them, because it's confusing.
And here we see a live example of that confusion!
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56215
|
|
|
Indeed! Remember that just because you can do something doesn't mean that you should!
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
An example of what Bear says: it is possible to open a car door when travelling at 99mph. Something you can do, but don't do . . . at least not twice
|
 |
Luigi Plinge
Ranch Hand
Joined: Jan 06, 2011
Posts: 441
|
|
|
Would it be utterly horrible to type?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56215
|
|
|
To me, yeah. It's much less clear than each in their statement. Why obfuscate the code when you can make it clear?
|
 |
Luigi Plinge
Ranch Hand
Joined: Jan 06, 2011
Posts: 441
|
|
|
Saves typing... global RSI incidence rates must have rocketed since the introduction of Java generics...
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56215
|
|
|
In my opinion, saving typing is never a good excuse for obfuscating code.
|
 |
Elchin Asgarli
Ranch Hand
Joined: Mar 08, 2010
Posts: 222
|
|
Bear Bibeault wrote:In my opinion, saving typing is never a good excuse for obfuscating code.
Can't agree more. Its just not comfortable later to read obfuscated code, rather than later trying to read obfuscated code, its easier to type few letters more.
|
Personal page, SCJP 6 with 91%, SCWCD 5 with 84%, OCMJD
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
Luigi Plinge wrote:Saves typing... global RSI incidence rates must have rocketed since the introduction of Java generics...
You'll be pleased with one of the new features in Java 7, which will allow you to write this:
instead of:
|
 |
Luigi Plinge
Ranch Hand
Joined: Jan 06, 2011
Posts: 441
|
|
Good news... but I think there are still quite a few redundant characters in that code.
*runs off to start learning Groovy*
|
 |
 |
|
|
subject: Valid code, but what does it mean?
|
|
|