Bagesh Sharma :
I want to create my custom object using the assignment operator as the string does.
For example,
If I want to create an Object of employee class in a simple way like -
Class Employee{
private String name;
private int age;
private String country;
}
Employee employee = "Bagesh,27,India";
So is it possible to create an object the same way String class creates? or anyone can suggest the internal working of string assignment operator object creation.
I have already searched for it on many links but didn't get a complete answer.
tbsalling :
No, that is not possible.
The String
class is special in Java. The compiler has special knowledge about it and knows how to generate byte code for e.g. the =
operator (assign reference to a preallocated string in the String pool) and +
operator (call .concat()
).
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=415796&siteId=1