You can't directly assign value to Object like Strings.
If you really want to achieve the same thing, I would suggest you to create a Factory of pre-defined initialized objects and get the required object from Factory by using Prototype
pattern or FactoryMethod
pattern.
Sample code:
import java.util.concurrent.atomic.*;
public class PrototypeFactory
{
public class NumberPrototype
{
public static final String THIRTY_TWO = "32";
public static final String FORTY_ONE = "41";
}
private static java.util.Map<String , AtomicInteger> prototypes = new java.util.HashMap<String , AtomicInteger>();
static
{
prototypes.put(NumberPrototype.THIRTY_TWO, new AtomicInteger(32));
prototypes.put(NumberPrototype.FORTY_ONE, new AtomicInteger(43));
}
public static AtomicInteger getInstance( final String s) {
//return (AtomicInteger)(prototypes.get(s)).clone();
return ((AtomicInteger)prototypes.get(s));
}
public static void main(String args[]){
System.out.println("Prototype.get(32):"+PrototypeFactory.getInstance(NumberPrototype.THIRTY_TWO));
}
}
output:
Prototype.get(32):32