以下代码是否有效?
void myMethod (Class classType) {
if (classType == MyClass.class) {
// do something
}
}
myMethod (OtherClass.class);
Run Code Online (Sandbox Code Playgroud)
如果没有,那么我可以检查传递的.class(Class Type)类型是否为MyClass?
感谢名单!
我有一个 X509Certificate,我将它写入/打印到一个文件中,如下所示。(我不是在写编码字节,因为我想阅读证书的内容)
X509Certificate cer = generateCertificate(); // cer is DER encoded
writeToFile( cer.toString() ); // cer.toString() converts DER to UTF/ASCII???
Run Code Online (Sandbox Code Playgroud)
后来我想将此文件(以上)作为字符串读取并创建一个新的 X509Certificate。
String cerStr = readCerFromFile(); // Read what is written above. In ASCII/ UTF format
ByteArrayInputStream bais = null;
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
bais = new ByteArrayInputStream(cerStr.getBytes());
return (X509Certificate) cf.generateCertificate(bais);
} ...
Run Code Online (Sandbox Code Playgroud)
这将引发以下异常。
Java.security.cert.CertificateParsingException: Invalid DER-encoded certificate data
Run Code Online (Sandbox Code Playgroud)
很明显,我没有将 cerStr 转换为 DER 格式(我不知道是否可以转换为 DER )。任何人都可以解释如何从未编码的字符串创建 X509Certicate 。
提前致谢。!
在三层体系结构中,有表示/ Web层,服务层和数据库层。但是,在我最近从事的项目中,我看到了对我来说是新的Manager层。您能否解释一下服务层/类与管理器层/类之间的区别?
还请提出一些用于学习3层体系结构和相关模式的好书。(对于Java / Java EE应用程序)