2013-10-23 2 views
0

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

+2

관련 코드를 게시하십시오; 당신은 어디서나 정의 된'insertAfter'를 가지고 있지 않습니다. 대부분 'T'를 받아 들일 가능성이 있지만 오류가 말하는 것처럼 int에 전달하려고합니다. – chrylis

+0

자바 프리미티브는 객체로 처리되지 않습니다. –

+0

숫자 '11'은 모든 'T'에 대해 'T'유형이 아닙니다. * 물론 그것은 당신에게 오류를 줄 것입니다. – Boann

답변

1

을하고 그것은 당신이 (당신이 우리를 표시하지 않은 한) insertAfter(T value)이라는 방법을 쓴 것 같습니다해야합니다. 이제 CDLListTest<T>을 처리 할 때 T이 어떤 클래스 또는 인터페이스가 될 수 있다고 언급 할 것입니다. 따라서 insertAfter으로 전화 할 때 전달하는 값은 T이어야합니다. 하지만 T 대신 int을 전달 중입니다.

어느

T을 통과 insertAfter에 전화를 변경하거나 매개 변수 유형 int의되도록 insertAfter 방법의 서명을 변경합니다.

관련 문제