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을 사용할 수 없습니다
Re 유형 주석, 나는 그 메시지가 '더 많은 주석 추가'를 말하는 것처럼 보였다고 생각합니다. – Joe
답변을 주셔서 대단히 감사합니다. 나는 또 다른 문제에 직면 해있다. 아마 1 분 남겨 둘 수 있을까? http://stackoverflow.com/questions/25786493/classnotfound-error-trying-to-implement-clojure-protocol-with-a-deftype – Joe