How can I convert a String to Object? Actually, I want to set
clientSession.setAttribute("username", "abc")
However, it shows
java.lang.String given, required java.lang.Object.
This question is related to
java
A String is a type of Object. So any method that accepts Object as parameter will surely accept String also. Please provide more of your code if you still do not find a solution.
String extends Object, which means an Object. Object o = a;
If you really want to get as Object, you may do like below.
String s = "Hi";
Object a =s;
Source: Stackoverflow.com