0

给定 java 类“抽象凭证”并派生“EmailPassword”/“OAuth”类。

和接口 CredentialsStorage,具有适当的实现 EmailPasswordStorage 和 OAuthStorage

我需要用三元组创建某种数组:存储、有效凭据、无效凭据)

所以我从这个开始:

type T <: Credentials

type S <: CredentialsStorage[T]

private var testData: Array[(S, T, T)] = Array(
  (emailStorage, validEmailPasswd, new EmailPasswordCredentials("1", "2")),
  (oAuthStorage, validAuthToken, new OAuthCredentials("invalid auth token", OAuthService.FACEBOOK))
)

但是这不会编译

error: type mismatch;
found   : storage.EmailPasswordStorage[credentials.EmailPassword]
required: CredentialsStorageTest.this.S
(emailStorage, validEmailPasswd, new EmailPasswordCredentials("1", "2")),

我该如何解决这个问题,这里依赖/存在类型的正确定义是什么?

UPD我用元组类型本身的定义解决了这个问题:

type T[A] = (CredentialsStorage[A],A,A)

val testData : Array[T[_ <: Credentials]] = ...
4

1 回答 1

2

type T <: Credentials定义一个抽象类型。您尚未定义T此实例中的内容。尝试包括type T = credentials.EmailPasswordtype S = storage.EmailPasswordStorage[T]

于 2012-11-20T13:11:19.377 回答