wood burning stoves*
The moose likes Java in General and the fly likes Hairy about generics (Challenge) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hairy about generics (Challenge)" Watch "Hairy about generics (Challenge)" New topic
Author

Hairy about generics (Challenge)

Peter Hsu
Ranch Hand

Joined: Aug 25, 2006
Posts: 72
Hi

I was trying to create a code example for a (as I imagine) useful pattern I would like to call "friend pattern". The name of the pattern is inspired by the C++ "friend" keyword.

Imagine you have a bunch of classes that stores some data, each with different properties and you would like to create a editor (friend) for each of these classes. Of course, these classes has no business of knowing how they can be edited and we would like to define separate classes to edit them. The pattern I called "friend" pattern provides a way other programmers to add their own data classes and editors without having to rebuild any existing component.

I tried to use generics in my example code as much as possible but when I write the last two line I realized I am stuck. I didn't think this through and the last two line won't compile. I realized I might have to change quite a bit of code and remove some of the generics usage. I would really hate that because I find java's generic very self-documenting and make my idea easy to read and understand.

Can someone help me to make minimum number of changes and make the code compile?





thanks
Peter Hsu
Ranch Hand

Joined: Aug 25, 2006
Posts: 72
Oh by the way...
I just wanted to say I know why this code wouldn't compile, but I realize if I want to make the code compile I would have to remove a while bunch of generics and I want to minimize that
Peter Hsu
Ranch Hand

Joined: Aug 25, 2006
Posts: 72
found solution

line 40~43:




line 82~92

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hairy about generics (Challenge)
 
Similar Threads
Generics
Generics
generics
Generics
Generics