3

请帮助我解决此代码中的模棱两可的调用。

fac.newtransform()fac.new signedinfo()给出错误说:

引用newTransform不明确,method newTransform(String,TransformParameterSpec)inXMLSignatureFactory和 method newTransform(String,XMLStructure)in 都XMLSignatureFactory匹配

我怎样才能调用实际的函数XMLSignatureFactory

   XMLSignatureFactory fac =XMLSignatureFactory.getInstance("DOM",
                (Provider) Class.forName(providerName).newInstance());

   Reference ref =fac.newReference("",fac.newDigestMethod(DigestMethod.SHA1, null),
    Collections.singletonList(fac.newTransform(Transform.ENVELOPED, null)),null, null);


   SignedInfo si = fac.newSignedInfo
       (fac.newCanonicalizationMethod
         (CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS, 
             null), 
        fac.newSignatureMethod(SignatureMethod.DSA_SHA1, 
            null),
        Collections.singletonList(ref));
4

2 回答 2

6

您必须转换第二个参数:

newTransform("foo", (XMLStructure) null)

您收到模棱两可的警告,因为null这两种方法都是有效的参数。您需要添加(XMLStructure)强制转换以告诉编译器您要设置的对象的类型null..

于 2013-07-01T07:19:52.837 回答
2
newTransform(Transform.ENVELOPED, null);

此调用不明确,因为null将匹配方法签名newTransform(java.lang.String algorithm, XMLStructure params)newTransform(java.lang.String algorithm, TransformParameterSpec params)。投射null

newTransform("foo", (XMLStructure) null)
于 2013-07-01T07:22:26.413 回答