This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Valid code, but what does it mean? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Valid code, but what does it mean?" Watch "Valid code, but what does it mean?" New topic
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
    
    2

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
    
    3

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
    
    2

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
    
  13

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
    
    4
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
    
  13

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
    
  13

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
    
    3

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*
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Valid code, but what does it mean?
 
Similar Threads
ArrayList
Please Help - Remove only the duplicated ITEM and NOT the original item that was duplicated.
Alignment for centering text in JTextPane does not work
HashSet and the empty operator
describe and apply the "program to an interface" principle