Tôi đang gặp một số vấn đề với các loại. Trong trường hợp này, tôi có hai đặc điểm với các phương thức cơ sở, và một trong số chúng phụ thuộc vào phương pháp khác. Sau đó tôi có hai triển khai cho họ. Bạn có biết có gì sai ở đây không?Đặc tính không phù hợp với giới hạn tham số loại
Trình biên dịch đang nói:
type arguments [ImplDefinition,ImplDto,ImplDtoIdentifier] do not conform to trait ChildOperations's type parameter bounds [C <: Types.BaseT[A,I],A <: Types.IDObj[I],I <: IIdentifier]
[error] class ImplOperations extends Parent2(new ImplDefinition) with ChildOperations[ImplDefinition, ImplDto, ImplDtoIdentifier] {
Mã:
/*
* Generic Implementation
*/
object Types {
type IDObj[I <: IIdentifier] = AnyRef {def id: I}
type BaseT[A, I <: IIdentifier] = Parent1[A] {
def id: Foo[I]
}
}
trait IIdentifier extends Any {
def id: Long
override def toString = id.toString
}
class Parent1[A](a: String)
class Foo[A](a: String)
trait ChildDefinition[A <: Types.IDObj[I], I <: IIdentifier] {
self: Parent1[A] =>
def id(a: A): Foo[I]
}
class Parent2[A](a: A)
trait ChildOperations[C <: Types.BaseT[A, I], A <: Types.IDObj[I], I <: IIdentifier] {
self: Parent2[C] =>
def get(identifier: I): Option[A]
}
/*
* Concrete Implementation
*/
case class ImplDtoIdentifier(id: Long) extends IIdentifier
case class ImplDto(id: ImplDtoIdentifier, name: String)
class ImplDefinition extends Parent1[ImplDto]("Value") with ChildDefinition[ImplDto, ImplDtoIdentifier] {
override def id(a: ImplDto): Foo[ImplDtoIdentifier] = ???
}
class ImplOperations extends Parent2(new ImplDefinition) with ChildOperations[ImplDefinition, ImplDto, ImplDtoIdentifier] {
self =>
override def get(identifier: ImplDtoIdentifier): Option[ImplDto] = ??? // here I will use the id method from ImplDefinition
}
Cá nhân, tôi muốn có một cái nhìn và cung cấp cho bạn một gợi ý, nhưng tôi don' Tôi có đủ thời gian để tìm ra mọi thứ đang diễn ra ở đây. Bạn có 11 lớp/đặc điểm và không bao gồm các loại bổ sung. Bạn sẽ có cơ hội phản hồi tốt hơn nếu bạn thu hẹp ví dụ xuống [MCVE] (http://stackoverflow.com/help/mcve). – slouc
Tôi đã thực hiện thao tác này và xóa tất cả các phần còn lại. Nhưng bạn nói đúng, nó vẫn còn rất lớn. Bạn không chắc chắn nếu nó giúp nhưng, nếu bạn loại bỏ các lớp ImplOperations nó biên dịch. Vấn đề đang xác minh các loại ChildOperarions. – rtfpessoa