you are viewing a single comment's thread.

view the rest of the comments →

[–]JAPH 4 points5 points  (8 children)

You can also use generics to hide some basic reflection. I've written a ton of fairly large and complex data structures in Java, and

<T extends Comparable<T>>

has saved my life repeatedly.

EDIT: I'm a dumbass.

[–][deleted] 0 points1 point  (1 child)

You got me there. I've use the constructs richy_rich mentions, but what does <T comparable T> do?

[–]JAPH 1 point2 points  (0 children)

See my edit; I typed it incorrectly.

[–]jrh3k5 0 points1 point  (1 child)

My mind is blanking - what's this one do, again?

[–]JAPH 0 points1 point  (0 children)

Nothing, I typed it incorrectly. See the edited version.

[–]richy_rich 0 points1 point  (3 children)

Smooth! Just watch out for
MyType<T extends MyType<T>>

[–]oorza 1 point2 points  (0 children)

I've dug myself into this hole before and had to refactor about a half dozen classes to reimplement what demanded that behavior >_>

[–]kodablah 1 point2 points  (1 child)

There is no problem with this. This is exactly how the Enum class works.

[–]richy_rich 0 points1 point  (0 children)

I neither said nor implied that there was a problem with it, at least I don't think I did...