When learning about String literals vs String objects, I came across the fact that there are 2 possible ways to instantiate a variable of type String
//Using literals
String s1 = "text";
//Using constructor
String s2 = new String("text");
I was wondering if it is possible to somehow create an class and instead of instantiating it with a constructor, one could instantiate it using a literal
This is what I mean
class Value {
int value;
//Some methods
}
Value val = 10; //Program automatically sets val.value = 10