zoukankan      html  css  js  c++  java
  • scala2.10.x case classes cannot have more than 22 parameters

    问题

    这个错误出现在case class参数超出22个的时候。

    case classes cannot have more than 22 parameters
    

    在scala 2.11.x版本以下时case class 的参数最多为22个,如果超过这个参数又不能升级时(比如目前spark依赖于2.10.x)要怎么办?

    解决方案

    这里举个26个参数的例子,其余情况依此类推

    class ABC (
                a : String,
                b : String,
                c : String,
                d : Long,
                e : Long,
                f : Map[String,String],
                g : List[String],
                h : List[String],
                i : List[String],
                j : List[String],
                k : List[String],
                l : List[String],
                m : List[String],
                n : List[String],
                o : List[String],
                p : List[String],
                q : List[String],
                r : List[String],
                s : List[String],
                t : List[String],
                u : List[String],
                v : List[String],
                w : List[String],
                x : List[Map[String,String]],
                y : List[Map[String,String]],
                z : List[Map[String,String]]) extends Product with scala.Serializable {
    
      def productElement(n: Int) = n match {
        case 0 => a
        case 1 => b
        case 2 => c
        case 3 => d
        case 4 => e
        case 5 => f
        case 6 => g
        case 7 => h
        case 8 => i
        case 9 => j
        case 10 => k
        case 11 => l
        case 12 => m
        case 13 => n
        case 14 => o
        case 15 => p
        case 16 => q
        case 17 => r
        case 18 => s
        case 19 => t
        case 20 => u
        case 21 => v
        case 22 => w
        case 23 => x
        case 24 => y
        case 25 => z
      }
    
      def canEqual(that: Any) = that.isInstanceOf[ABC]
      def productArity = 26
    }
    
    //之后使用
    new ABC(...)解决该问题
  • 相关阅读:
    《Programming WPF》翻译 第6章 3.二进制资源
    《Programming WPF》翻译 第5章 前言
    谈谈粒子系统
    GameFramework的初步设计
    引擎层次化设计
    关于HeapCreate(1)
    新的引擎ZeusEngine
    最短路径算法介绍
    Max导出插件
    游戏中的光影效果
  • 原文地址:https://www.cnblogs.com/zhangyunlin/p/6168178.html
Copyright © 2011-2022 走看看