This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 18541
    
    8

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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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: 18541
    
    8

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: 60794
    
  65

Indeed! Remember that just because you can do something doesn't mean that you should!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
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: 60794
    
  65

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: 60794
    
  65

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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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
Please Help - Remove only the duplicated ITEM and NOT the original item that was duplicated.
HashSet and the empty operator
ArrayList
Alignment for centering text in JTextPane does not work
describe and apply the "program to an interface" principle