• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generics: Nested Map Declaration  RSS feed

 
Aryeh Golob
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a nested Map and the generics declaration is pretty unruly.



Is there any way to shorten things?

Thanks,
Aryeh
 
Daniel Chemko
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If thats what you need, then why worry about syntax?

I'd consider replacing the nested maps into concrete objects that may have maps within them, but only if the need requires. In itself, the data structure is very complicated, so that when you're using generics, you could get lost in the nesting.

Modeling complex structures are hard, but generics makes sure you don't make obvious mistakes in bad casting.
 
Aryeh Golob
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel and thanks for your response!

I would normally use objects in such an instance, but this data structure is used for printing purposes only.

Was just curious if there as an easier way, but I can live with this (I guess .

-Aryeh
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
report generation is one of the ugliest parts of coding,
if it's ugly, it's ugly,
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugly workaround: create subclasses that take away the generics:

That would replace your declaration to Map<String, SetMapMap>.

But like I said, it's ugly. Plus you loose the advantages of programming against interfaces.
 
Aryeh Golob
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting work-around. Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!