int 인수로 일반 클래스의 메소드를 호출 할 때 다음 오류가 발생합니다.X 유형의 메소드 X가 인수에 적용되지 않습니다 (int)
The method insertAfter(T) in the type CDLList<T>.Writer is not applicable for the arguments (int)
일반 클래스 코드는
public class CDLList<T> {
public Element Head;
static int count;
public CDLList(T v)
{
Head = new Element(v);
}
public class Element
{
public T data;
public Element next;
public Element prev;
Element(T v)
{
data = v;
prev=null;
next=null;
count++;
}
public T value()
{
return data;
}
}
public Element head()
{
return Head;
}
public Cursor reader(Element from)
{
Cursor CurrCursor=new Cursor(from);
return CurrCursor;
}
public class Cursor
{
public Element current;
Cursor(Element v)
{
current=v;
}
public Element current()
{
T temp;
temp = current.value();
System.out.println(temp);
return current;
}
public void previous()
{
current = current.prev;
}
public void next()
{
current = current.next;
}
public Writer writer()
{
Writer nwriter = new Writer(current);
return nwriter;
}
}
public class Writer
{
public Element current;
Writer(Element temp)
{
current=temp;
}
public boolean delete()
{
Element Td1,Td2;
Td1 = current.prev;
Td2 = current.next;
current=null;
Td1.next = Td2;
Td2.prev = Td1;
return true;
}
public boolean insertBefore(T val)
{
Element t = new Element(val);
Element t2 = current.prev;
t2.next=t;
current.prev=t;
t.next=current;
t.prev=t2;
return true;
}
public boolean insertAfter(T val)
{
Element t = new Element(val);
Element t1 = current.next;
t.next=t1;
t1.prev=t;
current.next=t;
t.prev=current;
return true;
}
}
가}
일반 클래스를 구현하는 클래스는 내가 다른 일반 클래스를 확장 할 경우 작동
public class CDLListTest<T> extends CDLList<T> implements Runnable {
Cursor cursor;
public CDLListTest(T v) {
super(v);
// TODO Auto-generated constructor stub
Element t1= new CDLList.Element(20);
-----------------------
temp.writer().insertAfter(11); -- Getting error here
입니다 자식 일반 클래스 및 자식 일반 clas 확장 주요 기능을 포함하는 클래스로.
무엇이 여기에 있습니까? 수업이 일반적이기 때문에 작동해야합니다. 많은 답변을 찾을 수 없기 때문에 많은 답변을 찾을 수 없습니다.
편집 : 어제 나는이 질문을 올리면서 어쩔 수없이 미안합니다. 사과드립니다. 질문을 명확하게하기 위해 편집했습니다.
Edit2가 : 고정 그것을 public class CDLListTest<T> extends CDLList<T>
public class CDLListTest<T> extends CDLList
관련 코드를 게시하십시오; 당신은 어디서나 정의 된'insertAfter'를 가지고 있지 않습니다. 대부분 'T'를 받아 들일 가능성이 있지만 오류가 말하는 것처럼 int에 전달하려고합니다. – chrylis
자바 프리미티브는 객체로 처리되지 않습니다. –
숫자 '11'은 모든 'T'에 대해 'T'유형이 아닙니다. * 물론 그것은 당신에게 오류를 줄 것입니다. – Boann