Any tool to convert java raw code (a la java 1.4) into generics code

R

Royan

Hi all,

I wonder if someone has ever tried to convert Java 1.4 style code into
code that is using generics? What tools did you use and what was your
overall experience?

Thanks Roman.
 
R

Roedy Green

I wonder if someone has ever tried to convert Java 1.4 style code into
code that is using generics? What tools did you use and what was your
overall experience?

Just put the generics on the declare and the allocations. Compile. Fix
the errors. Run IntelliJ inspector and it will tell point you to the
places to pull the casts.

USING generic classes is a snap once you get the hang of it. You can
convert a program is a few minutes. The tricky part is writing a
Collections class. There you do it by monkey-see-monkey do looking
for a similar collection.
 
D

Daniel Pitts

Roedy said:
Just put the generics on the declare and the allocations. Compile. Fix
the errors. Run IntelliJ inspector and it will tell point you to the
places to pull the casts.

USING generic classes is a snap once you get the hang of it. You can
convert a program is a few minutes. The tricky part is writing a
Collections class. There you do it by monkey-see-monkey do looking
for a similar collection.
Programming should *never* be monkey-see-monkey-do! If you don't
understand what you're writing, then you're probably making a bug.
 
R

RedGrittyBrick

Programming should *never* be monkey-see-monkey-do! If you don't
understand what you're writing, then you're probably making a bug.

OTOH I find reading examples can be a useful way of arriving at a better
understanding.

According to Wikipedia monkey-see-monkey-do means different things in
different locales.
 
J

Jack

Royan a écrit :
Hi all,

I wonder if someone has ever tried to convert Java 1.4 style code into
code that is using generics? What tools did you use and what was your
overall experience?

In eclipse, select your project, right click on it, and then Refactor -> Infer Generic Type Arguments...

I guess you will have to check/correct some piece by hand, but most of it will be done automaticaly, depending how complexe is the code.
 
D

Daniel Pitts

RedGrittyBrick said:
OTOH I find reading examples can be a useful way of arriving at a better
understanding.
Agreed. Acceptable for training for programming. Not production
programming.
According to Wikipedia monkey-see-monkey-do means different things in
different locales.
But they both involve mimicry without understanding.
 
R

Roedy Green

There you do it by monkey-see-monkey do looking
for a similar collection.

What I meant by that is you can copy techniques without going to the
work of creating them from scratch. You have to understand them only
weakly -- knowing what the syntax means, without necessarily
developing the skill to compose them.
 
R

Royan

Ok, thank you everyone! I was also wondering what other people think
about this and I guess I got the common point :)
 
P

Patricia Shanahan

Jack said:
Royan a écrit :

In eclipse, select your project, right click on it, and then Refactor ->
Infer Generic Type Arguments...

I guess you will have to check/correct some piece by hand, but most of
it will be done automaticaly, depending how complexe is the code.

However, in my experience it works much better if the programmer has
some experience with generics.

I tried that technique shortly after I moved to 1.5, and got in such a
muddle that I had to revert out the changes and live with the warnings.

A few months later, I tried again on the same program and it all went
through very smoothly.

The difference was that I had been using generics in new code and
reading about them. During the first attempt, I was essentially
guessing, and making a lot of wrong choices, when Eclipse did not know
what to do. During the second attempt, I knew what I was doing.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top