1
我有一个具有泛型类型参数的案例类文档。现在我想在运行时获得TypeParamater类型。scala TypeTag的通用子类
我没有找到方法。
def toHtml[T <: DocumentType](doc: Document[T])(variableSubstitution: String => String): String = {
doc match {
case _ : Document[UnStructured] =>
case _ => //
}
}
我的文档类:
final case class Document[T <: DocumentType](chapterList: SortedSet[_ <: ChapterTrait[T]],
uniqueId: UUID = UUID.randomUUID(),
createDate: DateTime = DateTime.now(),
lastEdit: DateTime = DateTime.now(),
title: String = "",
version: Double = 1.0,
designSetting: DocumentDesignSettingTrait = DocumentDesignSetting(),
paperFormat: PaperFormat = A4,
headerList: List[PageMark] = Nil,
footerList: List[PageMark] = Nil,
preContent: PreContent = PreContent(),
postContent: PostContent = PostContent(),
author: Author = Author()) {
}
现在类型文件
sealed abstract class DocumentType
sealed abstract class StructuredDocumentType extends DocumentType
sealed abstract class SemiStructured extends StructuredDocumentType
//case object SemiStructured extends SemiStructured
sealed abstract class Structured extends StructuredDocumentType
//case object Structured extends Structured
sealed trait UnStructured extends DocumentType
//case object UnStructured extends DocumentType
我现在要找出哪些类型参数的文档为界。
有人有任何indea吗?
谢谢我会尝试它并尽快报告:) –
@Andréoops我的代码示例中有一个错误!对不起,这个 - 你应该在'T'上匹配,而不是在'doc'上,所以'typeOf [T]匹配{// ...' –
完美!谢谢!!!!! 'docType.tpe匹配{ 情况下若a =:= TYPEOF [非结构化] =>的println( “丹科”) 情况_ =>的println( “NEIN”) }' 很高兴听到正确的方式 –