Convert string to object

How to convert String to Object? In fact, I want to install

clientSession.setAttribute("username", "abc")

However he shows

java.lang.String given, required java.lang.Object.
+5
source share
3 answers

Java String - a Object. ( extends .) StringObject

Thus, you can get the link Objectthrough the assignment / initialization:

String a = "abc";
Object b = a;
+21
source

The string extends the object, which means the object. Object o = a;If you really want to get an Object, you can do it as shown below.

String s = "Hi";

Object a =s;
+2
source

- . , , , String. , , .

0

All Articles