The way of Java

ArbolOne arbolone at gmail.com
Sat Oct 26 10:17:37 UTC 2024


openjdk 17.0.13 2024-10-15
OpenJDK Runtime Environment (build 17.0.13+11-Debian-2deb12u1)
OpenJDK 64-Bit Server VM (build 17.0.13+11-Debian-2deb12u1, mixed mode, 
sharing)

public class NamesRecord{
     String id;
     ...
     // Setters and Getters
     public String getId(){
         return this.id;
     }
}

// Tres Dorritos Despues

main(){
     // aoe.getAllNames() returns an ArrayList<NamesRecord> object 
containing 13 elements
     // each element has a unique value
     var localArrayList = new ArrayList<NamesRecord>(aoe.getAllNames());
     // Display all id values in NamesRecord <=== Only prints one id 
NamesRecord::id value 13 times
     for(NamesRecord mydto : localArrayList){
         Integer pos = 1;
         System.out.print(pos + " ID is : ");
         System.err.print(mydto.getId() );
         pos++; // <== This value does not increment
     }

     // Second try, but same result
     for(int i = 10; i != localArrayList.size(); i++){
         System.out.print("\'i\' value is : ");
         System.err.println(i); // <== This value does increment
         Integer pos = 1;
         System.out.print(pos + " ID is : ");
         System.err.println(localArrayList.get(i).getId() );
         pos++; // <== This value does not get incremented
     }

     // Third try, but the similar result
     // Please note that the value of pos is never incremented <==
     NamesRecord[] array = new NamesRecord[localArrayList.size()];
         array = localArrayList.toArray(array);
         for(NamesRecord mydto : array){
             Integer pos = 1;
             System.out.print(pos + " ID is : ");
             p.setTimer(1);
             System.err.println(mydto.getId() );
             pos++; // <== This value does not get incremented
      }
}

Hello.
When looping through the ArrayList or even the Array[] to display the 
content stored in NamesRecord::id only one value is displayed; what I'd 
like to do is to display all the id values stored in the ArrayList or 
Array[] object.
However, as documented in the snip above, Java behaviour is not what I 
expected; mind you, I am fairly new in Java.
So, my question is, what am I doing wrong?
If there is something wrong, would you point it out and help me resolve 
it, please.

Is it a bug that came in the recent update I got from Debian?
If so, how do I report the bug to OpenJDK?

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20241026/5417b745/attachment-0001.htm>


More information about the jdk-dev mailing list