d******e 发帖数: 2265 | 1 You’re working with match expressions, actors, or other situations where
you want to use the case class syntax to generate boilerplate code,
including accessor and mutator methods, along with apply, unapply, toString,
equals, and hashCode methods, and more.
Solution
Define your class as a case class, defining any parameters it needs in its
constructor:
// name and relation are 'val' by default
case class Person(name: String, relation: String)
case class UsersBreakdown(nbUsers: Int, active: Int, waiting: Int, done: Int)
这个恶心程度赶上c++了。就为了 apply, tostirng, equals, hashcode 的默认实现。 | l******t 发帖数: 55733 | | p*****2 发帖数: 21240 | 3 这个东西太牛逼了
toString,
Int)
【在 d******e 的大作中提到】 : You’re working with match expressions, actors, or other situations where : you want to use the case class syntax to generate boilerplate code, : including accessor and mutator methods, along with apply, unapply, toString, : equals, and hashCode methods, and more. : Solution : Define your class as a case class, defining any parameters it needs in its : constructor: : // name and relation are 'val' by default : case class Person(name: String, relation: String) : case class UsersBreakdown(nbUsers: Int, active: Int, waiting: Int, done: Int)
| l**********n 发帖数: 8443 | 4 这个要怪Java
toString,
Int)
【在 d******e 的大作中提到】 : You’re working with match expressions, actors, or other situations where : you want to use the case class syntax to generate boilerplate code, : including accessor and mutator methods, along with apply, unapply, toString, : equals, and hashCode methods, and more. : Solution : Define your class as a case class, defining any parameters it needs in its : constructor: : // name and relation are 'val' by default : case class Person(name: String, relation: String) : case class UsersBreakdown(nbUsers: Int, active: Int, waiting: Int, done: Int)
| d******e 发帖数: 2265 | 5 准备看看能不能见个alias这个太别扭了
【在 p*****2 的大作中提到】 : 这个东西太牛逼了 : : toString, : Int)
| g*****g 发帖数: 34805 | 6 With defined fields, a java bean is a few clicks away to generate these
functions in a modern day IDE, probably taking less time to write than a
case class in Scala.
I am not denying Java is more verbose, but it also offers more flexibility,
like sometimes you want to override setter.
【在 l**********n 的大作中提到】 : 这个要怪Java : : toString, : Int)
| p*****2 发帖数: 21240 | 7
,
这个主要是为了pattern matching。Java8也没提供这个功能。
【在 g*****g 的大作中提到】 : With defined fields, a java bean is a few clicks away to generate these : functions in a modern day IDE, probably taking less time to write than a : case class in Scala. : I am not denying Java is more verbose, but it also offers more flexibility, : like sometimes you want to override setter.
| x***4 发帖数: 1815 | 8 有道理。case class就是为了和match一起用。
【在 p*****2 的大作中提到】 : : , : 这个主要是为了pattern matching。Java8也没提供这个功能。
| c******f 发帖数: 243 | 9 碰到过类似东西...特意用java写了个builder. | l******t 发帖数: 55733 | 10 不止。method应该进trait。case class就纯data
【在 x***4 的大作中提到】 : 有道理。case class就是为了和match一起用。
| | | g*****g 发帖数: 34805 | 11 Pattern matching is a rarely used feature at best. If you downcast a lot,
the design must be wrong.
【在 p*****2 的大作中提到】 : : , : 这个主要是为了pattern matching。Java8也没提供这个功能。
| p*****2 发帖数: 21240 | 12 没有pm java 用akka很痛苦吧?
【在 g*****g 的大作中提到】 : Pattern matching is a rarely used feature at best. If you downcast a lot, : the design must be wrong.
| p*****2 发帖数: 21240 | 13 不止 还要immutable
【在 l******t 的大作中提到】 : 不止。method应该进trait。case class就纯data
| l******t 发帖数: 55733 | 14
对
【在 p*****2 的大作中提到】 : 不止 还要immutable
| c*******9 发帖数: 9032 | 15 做framework,工具软件的会常用。
【在 g*****g 的大作中提到】 : Pattern matching is a rarely used feature at best. If you downcast a lot, : the design must be wrong.
|
|