I have odd behavior with a Java List<> class, which is overriding all values with the last one added.
Take for example the following code ...
import java.io.*;
import java.sql.*;
import java.lang.*;
import java.util.*;
public class alist
{
//
public static class item
{
public static String name;
public static long type;
item() {}
item( String n, long t )
{
name = n;
type = t;
}
public String toString()
{
return "name: " + name +
", type: " + String.valueOf( type );
}
}
public static void main(String [] args)
{
List<item> lst = new ArrayList<item>();
lst.add( new item( "abc", 0 ) );
lst.add( new item( "xyz", 1 ) );
for ( item i : lst )
System.out.println( i.toString() );
}
}
I would have expected this to output the following ...
name: abc, type: 0
name: xyz, type: 1
... but instead it prints ...
name: xyz, type: 1
name: xyz, type: 1
... ideas?
I'm sure it's something silly, where I simply cannot see the forest because of the trees. .