Mixing Java 1.5 code using generics w/ old 1.4 code

statik213

Golden Member
Oct 31, 2004
1,654
0
0
I've started writing a new application and would like to make use of generics -- sucker for c++ STL I guess.... but some of the (open source) libraries we'll be using have not yet been updated, and are meant to runk on java 1.4.x is it a bad idea to mix java 5 code in an environemnt where older code exits if it is possible at all?
Any links/resourses with guidelins on how to do this would be greatly appreciated.....
 

Stuxnet

Diamond Member
Jun 16, 2005
8,392
1
0
Do you have a need to recompile the open source? If so, just compile it under 1.4.2 and compile your code in 1.5.0. The 1.4 code will execute under 1.5.

1.5 was a sweet release. It's about damn time we got generics and, more importantly, structs.
 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
structs came with 1.5? Didn't know that....

OK... so if the libraries are in a jar file compiled w/ 1.4 and are in the classpath can I execute my java 1.5 code that is dependent on these libraries w/o a problem?

If that's gonna work, next thing is going to have to make JBuilder play nice w/ the 1.4 libraries and my 1.5 code.....
 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
Sounds good.....

Anything to watch out for when converting exisiting code to 1.5?

also.... are there any scripts that I can apply to retype existing containers to container<object>, so I can switch to 1.5 and be able to compile the project fairly quickly.... I could change the containers to the specfic types more gradually for exisiting code....
 

Stuxnet

Diamond Member
Jun 16, 2005
8,392
1
0
I don't know about scripts to convert, but the compiler will generate any warnings you need to be aware of. Converting 1.4 code to 1.5 shouldn't be any real task. In fact, unless your 1.4 code uses 1.5 keywords (like enum), you'll be fine.

Yeah, structs was introduced in 1.5. It's about darn time, too. Now you can create your own value types for simple objects. Enums are such a welcome sight, too. Gone are the days of writing rediculous "constants" classes. Now you get the same effect with built-in type-safety.

For once, I'm glad .NET is around. These features, along with autoboxing and autounboxing, showed up in .NET and to remain competitive, the JCP had to take action.
 

Stuxnet

Diamond Member
Jun 16, 2005
8,392
1
0
Oh, and the issue with JBuilder working with the 1.4 code shouldn't be any kind of issue, either. Just put the third party JARs in your ext directory, add them to your project, and mark them as required libraries. The fact that they were compiled under 1.4 is of no consequence, even if you're developing in JBuilder under 1.5.
 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
Originally posted by: jbourne77
Oh, and the issue with JBuilder working with the 1.4 code shouldn't be any kind of issue, either. Just put the third party JARs in your ext directory, add them to your project, and mark them as required libraries. The fact that they were compiled under 1.4 is of no consequence, even if you're developing in JBuilder under 1.5.

Well, when I add libraries in JBuilder I specify the jar files in the ext directory and also point it towards the source files and javadocs whenever possible. This make paramater insight and stuff to work well with external libraries (i.e. give detailed parameter information and informative class browsing).... it makes things a lot easier when dealing with unfamiliar libraries... if some of these libs require java 1.4 and my code require java 1.5 there may be problems..... anywayz that's not really important i can work around it....

thanks for the feedback guys.
 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
OK... I've made the transistion to 1.5 and it was really easy...
haven't rewritten my old code yet but that shouldn't be too difficult....
JBuilder didn't have an issues either, it actually worked a lot better than I could have hoped. I simply installed the jdk and the docs for the API and told JBuilder where the jdk was and it deduced the version, figured out where the source file are and stuff w/o any problems... it also doesn't seem to mind having non 1.5 libraries as well.
So the transsition was really really easy.....
Already begining to like 1.5...

again, thanks.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: jbourne77
I don't know about scripts to convert, but the compiler will generate any warnings you need to be aware of. Converting 1.4 code to 1.5 shouldn't be any real task. In fact, unless your 1.4 code uses 1.5 keywords (like enum), you'll be fine.

Yeah, structs was introduced in 1.5. It's about darn time, too. Now you can create your own value types for simple objects. Enums are such a welcome sight, too. Gone are the days of writing rediculous "constants" classes. Now you get the same effect with built-in type-safety.

For once, I'm glad .NET is around. These features, along with autoboxing and autounboxing, showed up in .NET and to remain competitive, the JCP had to take action.

I'm 99% sure Java 5 doesn't have structs. Enums yes, but not stucts per se.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
A class with only public fields and no methods is essentially a struct, but that's been there for any version of java. It's a pretty poor pattern though.

And just for the record, generics are a design-time feature only. There is no record of them in compiled code so it really doesn't matter what compiler or run time system you use, so long as you do use a 1.5 compiler for code that uses generics (and of course some of the other new features do require a 1.5 run time).
 

Stuxnet

Diamond Member
Jun 16, 2005
8,392
1
0
Originally posted by: AFB
Originally posted by: jbourne77
I don't know about scripts to convert, but the compiler will generate any warnings you need to be aware of. Converting 1.4 code to 1.5 shouldn't be any real task. In fact, unless your 1.4 code uses 1.5 keywords (like enum), you'll be fine.

Yeah, structs was introduced in 1.5. It's about darn time, too. Now you can create your own value types for simple objects. Enums are such a welcome sight, too. Gone are the days of writing rediculous "constants" classes. Now you get the same effect with built-in type-safety.

For once, I'm glad .NET is around. These features, along with autoboxing and autounboxing, showed up in .NET and to remain competitive, the JCP had to take action.

I'm 99% sure Java 5 doesn't have structs. Enums yes, but not stucts per se.


Yep - you're right... not sure what I was smoking when I wrote that. I've been toying with C#, so I must have got a signal crossed. Sure wouldn't be the first time hehe.

To the OP, congrats on the success with JBuilder. It's basically Visual Studio for Java developers. I love it.