| Author |
Generics: Nested Map Declaration
|
Aryeh Golob
Ranch Hand
Joined: Nov 12, 2006
Posts: 37
|
|
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
Joined: Feb 27, 2008
Posts: 32
|
|
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
Joined: Nov 12, 2006
Posts: 37
|
|
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
Joined: Nov 08, 2007
Posts: 457
|
|
report generation is one of the ugliest parts of coding, if it's ugly, it's ugly,
|
Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19230
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Aryeh Golob
Ranch Hand
Joined: Nov 12, 2006
Posts: 37
|
|
|
Interesting work-around. Thanks!
|
 |
 |
|
|
subject: Generics: Nested Map Declaration
|
|
|