void someMethod() { Socket s = someValidActualSocketObject(); if (s != null && s instanceof SSLSocket) { SSLSocket ssls = (SSLSocket)s; } }