哥们,我觉得你是不是应该这么些呢?
public interface PublicKey extends Key {
static final long serialVersionUID = 7187392471159151072L;
}
定义好接口protected void engineInitVerify(long key){
}
调用:engineInitVerify(PublicKey.serialVersionUID );
public interface PublicKey extends Key {
static final long serialVersionUID = 7187392471159151072L;
}
定义好接口protected void engineInitVerify(long key){
}
调用:engineInitVerify(PublicKey.serialVersionUID );
这句话中的参数实际是型参,只是个类型,如果你用long来写死的话灵活度会下降很多把接口作为型参的好处就是有非常大的灵活度,比如
public interface PublicKey extends Key {
static final long serialVersionUID = 7187392471159151072L;
}
调用
protected void engineInitVerify(PublicKey key){
long l = key.serialVersionUID;
....
}
这样所有实现PublicKey接口的类或继承PublicKey接口的接口都可以作为型参
public interface AnotherPublicKey extends PublicKey {}
调用时,可以把AnotherPublicKey传入,但是engineInitVerify方法不用改变
protected void engineInitVerify(PublicKey key){
long l = key.serialVersionUID;
....
}
你的回答我有几个地方不明白(调用时,可以把AnotherPublicKey传入,但是engineInitVerify方法不用改变
protected void engineInitVerify(PublicKey key){
long l = key.serialVersionUID;
....
})这里传入是什么意思?是作为参数传递或者是通过继承来实现?另外我现在想用一个vs.engineInitVerify(pubKey);来调用protected void engineInitVerify(PublicKey key)方法,可是pubKey是一个字符串类型,正如我上面说的他是一段公钥,我不知道如何将他的类型转换,否则总是类型错误我真没辙啊!
的serialVersionUID,你的protected void engineInitVerify(PublicKey key)不用改变,但是需要在其中判断类型。
2类型转换可以好好看看jdk的api定义
字符串 转 long
long l = Long.parseLong(String s);
long 转 字符串
String s = String.valueOf(long l);
谢谢了,希望得到你的帮助。
The Key interface is the top-level interface for all keys. It defines the functionality shared by all key objects. All keys have three characteristics: An Algorithm
This is the key algorithm for that key. The key algorithm is usually an encryption or asymmetric operation algorithm (such as DSA or RSA), which will work with those algorithms and with related algorithms (such as MD5 with RSA, SHA-1 with RSA, Raw DSA, etc.) The name of the algorithm of a key is obtained using the getAlgorithm method.
An Encoded Form
This is an external encoded form for the key used when a standard representation of the key is needed outside the Java Virtual Machine, as when transmitting the key to some other party. The key is encoded according to a standard format (such as X.509 or PKCS#8), and is returned using the getEncoded method.
A Format
This is the name of the format of the encoded key. It is returned by the getFormat method.
Keys are generally obtained through key generators, certificates, or various Identity classes used to manage keys. Keys may also be obtained from key specifications (transparent representations of the underlying key material) through the use of a key factory (see KeyFactory).