使用Guava获取私有域名时出错

时间:2014-11-14 20:06:41

标签: ant dns guava

我正在使用guava-18.0java1.6

考虑以下代码:

String host = null;
host = new URI(this.domain).getHost();
        Pattern p = Pattern.compile("[a-zA-Z]");
        Matcher m = p.matcher(host);
        if(m.find()){
            InternetDomainName domainName = InternetDomainName.from(host);
            this.domain = domainName.topPrivateDomain().name();
            System.out.println(this.domain);
        }
        else
            this.domain = host;

运行ant进行构建时,它会显示错误消息:

[javac] symbol  : method name()
[javac] location: class com.google.common.net.InternetDomainName
[javac]                             this.domain = domainName.topPrivateDomain().name();
[javac]                                                                        ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error

方法topPrivateDomain返回一个InternetDomainName对象,它有一个名为name()的方法。问题是什么?

1 个答案:

答案 0 :(得分:4)

InternetDomainName没有name()方法。它一直持续到15.0,但它在16.0被删除了。使用toString()