Monday, July 7, 2008

How Generic Shall it Be?

I have been writing the protocol API using Java 1.5 these days. There are some tempting features to use, but I'm not sure how evil they will be.

For instance, I use annotations to reflect clauses mentioned in the technical specifications:
@TechnicalRecommendations("1.2.1.3")
@PublishEvent(events={"UserNotification.EventType.ACCOUNT_CREATING", "UserNotification.EventType.ACCOUNT_CREATED"})
public void createUser(User caller, User targetUser) throws PermissionException;


I also use the generic feature:
public interface User<P extends Profile<?> extends Entity
public interface Profile<U extends User<?>> extends Entity


That sounds a bit funny hey. I haven't yet found a good guide on how you should use generic smartly. Comments?

- yc

4 comments:

Anonymous said...

YC, I don't know if I'm old school or something but I actually have not found Generics to be awfully useful. Or put it this way - I've got by until now without touching Generics and I can't bring myself to use it extensively.

If you do have some sort of revelation, do share ;)

Y said...

Hi Bernie,

I am new to generics too, as in, I didn't use it in my past projects as they're all required to be workable with 1.4.

The Jayway's guys must be using generics a lot, judging from how many annotations used in Qi4J.

Anyway, I have a short discussion in the JUG:

http://tech.groups.yahoo.com/group/myjug/message/7585

yc

Unknown said...

Use the right tools for the right ...

Jayway's guys are bloody cutting edge.

Anyway I only use generics for collections, like Bernie haven't found the need for Generic use in all my code.

But then again I'm using more and more Groovy instead of Java so I don't the much use of java at all in my codes.
:-D

Bacchus D said...

Generics are a good idea IMO but one that seems to be poorly implemented in mainstream languages (think C++ STL and now Java). I'm with Cakes in that I tend to use them for Collections since that usage is intuitive and perhaps left over from my not-so-fun days as a C++ loser.

Now that we're doing more Groovy these days at my company I've stopped thinking as much about types although I do miss the quality tooling that static typing can bring.