Appendix B. Retrofitting JDK 5.0 Code
This book uses JDK 5.0 features in many of its programs. This appendix summarizes the changes that you need to make to the sample programs so that they compile and run with JDK 1.4.
Enhanced for
Loop
The enhanced for
loop (or “for each” loop) must be turned into a traditional loop.
5.0 | 1.4 |
---|---|
for (type variable : array){ body} | for (int i = 0; i < array.length; i++){ type variable |
for (type variable : arrayList){ body} | for (int i = 0; i < arrayList.size(); i++){ type variable |
Generic Array Lists
You need to remove the type parameters and add casts to any get
operations.
5.0 | 1.4 |
---|---|
|
|
Get Core Java™ 2 Volume I - Fundamentals, Seventh Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.