我正在尝试使用泛型创建一个隐式类,这里是类
$ echo 'a b c d' |
awk 'FNR==1{for (i=1;i<=NF;i++) printf "$%d%s", i, (i<NF ? OFS : ORS)} 1'
$1 $2 $3 $4
a b c d
$ echo 'a b c d' |
awk 'FNR==1{for (i=1;i<=NF;i++) printf "$%d%s", i, (i<NF ? OFS : ORS)} 1' |
column -t
$1 $2 $3 $4
a b c d
这里是调用
object Utils {
implicit class optionUtils(option: Option[Any]) {
def sortedList[T]:List[T] = {
val list:List[T] = option.get.asInstanceOf[List[T]]
list.sorted[T]
}
}
}
但似乎排序不是编译,编译器说。
jsonResponse.get("products").sortedList[String]
知道如何使其有效吗?。
问候。
答案 0 :(得分:4)
您必须告诉编译器T
仅限于可订购类型。
def sortedList[T: Ordering]:List[T] = { ...