2014-09-11 4 views
0

org.joda.time.ReadableInstant을 구현하려고합니다. 그것은 일반적인 인터페이스를 상속하지만 분명히 중요하지 않아야합니다. The interface은 다음과 같습니다Clojure 레코드로이 일반 Java 인터페이스를 어떻게 구현합니까?

public interface ReadableInstant extends Comparable<ReadableInstant> { 
    long getMillis(); 
    Chronology getChronology(); 
    DateTimeZone getZone(); 
    int get(DateTimeFieldType type); 
    boolean isSupported(DateTimeFieldType field); 
    Instant toInstant(); 
    boolean isEqual(ReadableInstant instant); 
    boolean isAfter(ReadableInstant instant); 
    boolean isBefore(ReadableInstant instant); 
    boolean equals(Object readableInstant); 
    int hashCode(); 
    String toString(); 
} 

내 기록 :

(defrecord WeirdDate [year month day] 
    ReadableInstant 
    (^boolean equals [this ^Object readableInstant] (.equals (as-date this) readableInstant)) 
    (^int get [this ^DateTimeFieldType type] (get (as-date this) type)) 
    (^Chronology getChronology [this] (.getChronology (as-date this))) 
    (^long getMillis [this] (.getMillis (as-date this))) 
    (^DateTimeZone getZone [this] (.getZone (as-date this))) 
    (^int hashCode [this] (.hashCode (as-date this))) 
    (^boolean isAfter [this ^ReadableInstant instant] (.isAfter (as-date this) instant)) 
    (^boolean isBefore [this ^ReadableInstant instant] (.isBefore (as-date this) instant)) 
    (^boolean isEqual [this ^ReadableInstant instant] (.isEqual (as-date this) instant)) 
    (^boolean isSupported [this ^DateTimeFieldType field] (.isSupported (as-date this) field)) 
    (^Instant.toInstant [this] (.toInstant (as-date this))) 
    (^String toString [this] (.toString (as-date this)))) 

하지만 오류 얻을 :

java.lang.IllegalArgumentException: Must hint overloaded method: get 

는 내 타입이 잘못 힌트인가를? 뭔가 다른 점이 있습니까?

당신은 get 방법으로 유형을 구현하는 defrecord을 사용할 수 없습니다

답변

2

get이기 때문에, (사과는 Clojure mailing list where I've already asked a longer version of this question에 당신의 사람들을 위해, 나는 여기에 짧은 질문에 대답하기 쉬울 수 있습니다 생각) defrecord가 자동으로 구현하는 java.util.Map에 이미 정의되어 있습니다. 이 인터페이스를 구현하려는 경우 mappiness를 무시하고 일반 deftype 만 사용해야합니다. 또한 코드의 모든 유형 힌트는 완전히 불필요합니다. 컴파일러는 구현중인 인터페이스의 유형을 알고 있으므로이를 파악하는 데 도움이 필요하지 않습니다.

+0

Re 유형 주석, 나는 그 메시지가 '더 많은 주석 추가'를 말하는 것처럼 보였다고 생각합니다. – Joe

+0

답변을 주셔서 대단히 감사합니다. 나는 또 다른 문제에 직면 해있다. 아마 1 분 남겨 둘 수 있을까? http://stackoverflow.com/questions/25786493/classnotfound-error-trying-to-implement-clojure-protocol-with-a-deftype – Joe

관련 문제