I need help in getting value of a field using reflection. There is a class (SocketTest.class) which has server socket implementation, socket functionality is working fine. I'm trying to get hold of a socket field of this class and I intend to call its getInputStream() method to accept inputs. Following code is giving me IllegalArgumentException
-- Can not set java.net.Socket field com.test.SocketTest.socket to java.lang.Class
Field socketField = SocketTest.class.getDeclaredField("socket");
socketField.setAccessible(true);
Class<?> socketTest = "SocketTest".getClass();
Socket socket = (Socket)socketField.get(socketTest);
Aucun commentaire:
Enregistrer un commentaire