2014-03-05 4 views
3

는 다음과 같은 예를 생각해클래스 클래스 기본 속성으로 scalaz.Tagged 작업을하는 방법?

import scalaz._ 

object TaggedExample { 
    sealed trait Test 

    def Test[A](a: A): A @@ Test = Tag[A, Test](a) 
} 

case class TaggedAttribute(l: Long @@ TaggedExample.Test) 
그것은 다음 이유 컴파일 할 수 없게됩니다

: 내 이해에

scalac: type mismatch; 
found : Double 
required: AnyRef 
Note: an implicit exists from scala.Double => java.lang.Double, but 
methods inherited from Object are rendered ambiguous. This is to avoid 
a blanket implicit which would convert any scala.Double to any AnyRef. 
You may wish to use a type ascription: `x: java.lang.Double`. 

, 그것으로 인한 경우 클래스 컴파일러 코드 생성의 일부 세부 사항에 발생한다 (단순 때문에 def test(l: Long @@ TaggedExample.Test) = l은 정상적으로 컴파일됩니다.)

우리는 성공할 것

case class TaggedAttribute(l: java.lang.Long @@ TaggedExample.Test) 

컴파일하는 경우 클래스 정의를 변경하는 경우.

질문은 : (다시, lnull 등이 될 수 있습니다) ljava.lang.Long의 유형을 변경하지 않고이 scalac 오류를 방지 할 수있는 방법이 있습니까?


업데이트 여전히 Tagged type : type mismatch 질문을 발견하고 바로 게시 후 대답하지만,

는 : java.lang.* 박스 타입의 사용을 방지 할 수있는 방법이 될 수있다.

답변