哥们,我觉得你是不是应该这么些呢?
public interface PublicKey extends Key {
    static final long serialVersionUID = 7187392471159151072L;
}
定义好接口protected void engineInitVerify(long key){
}
调用:engineInitVerify(PublicKey.serialVersionUID );

解决方案 »

  1.   

    protected void engineInitVerify(PublicKey key)
    这句话中的参数实际是型参,只是个类型,如果你用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;
        ....
    }
      

  2.   

    呵呵,其实我也觉得这么写好啊,可接口和源方法都是从网上下载的jar包。如果改了这个不知道会不会改动其他的文件.而现在我有的这段字符串是已经定义好的公钥。我用PublicKey定义它出现E:\cryptix\RSAVerify.java:67: incompatible types错误。不知道怎样才能将它定义成PublicKey的形式。请教了!另外我比较菜,问的问题不对的地方别见笑!
      

  3.   

    RobertDeNiro() :
    你的回答我有几个地方不明白(调用时,可以把AnotherPublicKey传入,但是engineInitVerify方法不用改变
    protected void engineInitVerify(PublicKey key){
        long l = key.serialVersionUID;
        ....
    })这里传入是什么意思?是作为参数传递或者是通过继承来实现?另外我现在想用一个vs.engineInitVerify(pubKey);来调用protected void engineInitVerify(PublicKey key)方法,可是pubKey是一个字符串类型,正如我上面说的他是一段公钥,我不知道如何将他的类型转换,否则总是类型错误我真没辙啊!
      

  4.   

    是作为参数传递,因为如果子类AnotherPublicKey继承了你的PublicKey,或是重载PublicKey
    的serialVersionUID,你的protected void engineInitVerify(PublicKey key)不用改变,但是需要在其中判断类型。
    2类型转换可以好好看看jdk的api定义
       字符串 转 long 
        long l = Long.parseLong(String s);
       long 转 字符串
        String s = String.valueOf(long l);
      

  5.   

    RobertDeNiro:那PublicKey这个类型的数据用long类型的传递过去也不对啊!我找了很多方法,比方说用X.509编码方式转换结果也不认String类型。即使用long类型的转换也报错。真郁闷!不知道你能不能用QQ或者MSN,我的是75088832和 [email protected]
    谢谢了,希望得到你的帮助。
      

  6.   

    public interface Key extends Serializable
    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).