java - 为什么我不能从方法声明中单独导入?(java)

标签 java eclipse import base64 decode

我编写了一个简单的程序来解码我拥有的 Base64 编码字符串。我使用 eclipse 搜索了一种方法来执行此操作,并发现方法 javax.xml.bind.DatatypeConverter.parseBase64Binary(String s) 正是这样做的。我发现当我使用该方法的完整位置时,程序运行良好:

public static void main(String args[]) {
String s = "cGFzc3dvcmQ6IGlsb3ZlbXlzZWxmISEx";
byte[] converted = javax.xml.bind.DatatypeConverter.parseBase64Binary(s);
System.out.println(new String(converted));
}

但由于某种原因,当我尝试导入位置时,Eclipse 给了我一个错误:

导入:

import javax.xml.bind.DatatypeConverter.*;

第一个代码中的新行 3:

 byte[] converted = javax.xml.bind.DatatypeConverter.parseBase64Binary(s);

我在新行 3 上遇到错误:

 The method parseBase64Binary(String) is undefined for the type **name of class**

我很乐意提供解释。

最佳答案

您需要进行静态导入:

import static javax.xml.bind.DatatypeConverter.*;

import static javax.xml.bind.DatatypeConverter.parseBase64Binary;

然后您将能够执行以下操作:

byte[] converted = parseBase64Binary(s);

更多信息:

关于java - 为什么我不能从方法声明中单独导入?(java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28696224/

相关文章:

ruby-on-rails - 如何在 eclipse aptana 插件中调试 ruby​​ on rails

javascript - Firefox 扩展中的 Google 搜索 API

swift - 尝试导入图像时出现 Metadata.framework 错误

java - RSA 在 ios 中加密和在 java 服务器中解密不起作用

java - 错误: Illegal Start Of type: for loop [duplicate]

java - Android 库 Gradle 发布 JAR

eclipse - 如何为 Mylyn 任务选择本地存储库的位置?

Java Map::hashCode() 冲突 - 为什么?

即使在 Eclipse 中使用 JDK 1.7,java.nio.file 也无法正常工作

import - 去导入github,怎么设置?