Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Valid code, but what does it mean?

 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


bset is initialized but aset isn't - is it interpreted as something in generics?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15483
43
Android IntelliJ IDE Java Scala Spring
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed! Remember that just because you can do something doesn't mean that you should!
 
Campbell Ritchie
Sheriff
Pie
Posts: 50206
79
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it be utterly horrible to type?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saves typing... global RSI incidence rates must have rocketed since the introduction of Java generics...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion, saving typing is never a good excuse for obfuscating code.
 
Elchin Asgarli
Ranch Hand
Posts: 222
Chrome Eclipse IDE Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15483
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good news... but I think there are still quite a few redundant characters in that code.



*runs off to start learning Groovy*
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic