【发布时间】:2020-08-09 02:44:17
【问题描述】:
我写了以下代码:
array(0).getClass match {
case Int.getClass =>
byeBuffer = ByteBuffer.allocate(4 * array.length)
case Long.getClass =>
ByteBuffer.allocate(8 * array.length)
case Float.getClass =>
ByteBuffer.allocate(4 * array.length)
case Double.getClass =>
ByteBuffer.allocate(8 * array.length)
case Boolean.getClass =>
ByteBuffer.allocate(1 * array.length)
不过,过度使用getClass 让我觉得很笨拙。
有没有更好的写法?
【问题讨论】:
标签: scala functional-programming pattern-matching