找不到符号 - 方法(通用方法)

时间:2016-03-10 03:14:22

标签: java compiler-errors

我有两节课。 一个是短语课,

  var responseString = response.result.value?.stringByReplacingOccurrencesOfString("\r\n", withString: "")
            responseString = responseString?.stringByReplacingOccurrencesOfString("<string xmlns=\"webservices.fmx.bz/\">", withString: "")
            responseString = responseString?.stringByReplacingOccurrencesOfString("<?xml version=\"1.0\" encoding=\"utf-8\"?>", withString: "")
            responseString = responseString?.stringByReplacingOccurrencesOfString("</string>", withString: "")
            responseString = responseString?.stringByReplacingOccurrencesOfString("\"", withString: "")
            responseString = responseString?.stringByReplacingOccurrencesOfString( "{  ui: [    {      ", withString: "")
            responseString = responseString?.stringByReplacingOccurrencesOfString( "}  ]}", withString: "")
            responseString = responseString?.stringByReplacingOccurrencesOfString( "  ", withString: " ")
            var myStringArr = responseString?.componentsSeparatedByString(",")
            var companyNameStr = myStringArr![2].stringByReplacingOccurrencesOfString("cn:", withString: "")
            companyNameStr = companyNameStr.stringByReplacingOccurrencesOfString("&amp;", withString: "&")
            companyNameStr = companyNameStr.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
            NSUserDefaults.standardUserDefaults().setObject(companyNameStr, forKey: "companyName")

The Other是KeyedLinkedList。

import java.util.List;
import java.util.ArrayList;

@SuppressWarnings("unchecked")
public class Phrase
{
    List<String> papers = new ArrayList();
    String name = "";
    boolean multiple = false;

    public Phrase(String name, List list)
    {
        this.name = name;
        this.papers = list;
        if(list.size() > 1)
        {
             multiple = true;
        }
    }

    public Phrase(String name, String pName)
    {
        this.name = name;
        this.papers.add(pName);
        multiple = false;
    }

    public void addPaper(String paper)
    {
        papers.add(paper);
        multiple = true;
    }

    public String getPhrase()
    {
        return name;
    }

    public List<String> getPapers()
    {
         return papers;
    }
}

当我编译它时,我得到错误:“找不到符号 - 方法getPapers()”

我的Phrase类中显然有getPapers()方法,参数中的val是一个Phrase对象。我想知道我需要做些什么来解决这个问题。错误发生在put方法的一半。

1 个答案:

答案 0 :(得分:2)

public class KeyedLinkedList<K,Phrase>
//                             ^^^^^^

在这里,您要声明一个与Phrase类名称相同的类型变量并将其隐藏起来。使用类型Phrase声明的任何变量都引用此类型变量而不是Phrase类。

由于我不知道你的意图是什么,除了删除之外,我无法提出任何建议。

public class KeyedLinkedList<K>
顺便说一句,不要这样做:

List<String> papers = new ArrayList();
//                        ^^^^^^^^^

它被称为raw type,它很糟糕,并且没有理由使用它。请改为new ArrayList<String>