[英]Why doesn't Java expose a Compile time reflection based toString/hashCode/equals?
If I understand it correct, it should cost nothing in addition to actual function processing (of toString/hashCode/equals), if Java could compute the functions for the object for which compile-time reflection is requested. 如果我理解正确,那么如果Java可以为需要编译时反射的对象计算函数,那么除了实际的函数处理(toString / hashCode / equals)之外,它应该不花任何费用。
For the cases when objects are up/down casted the behavior is still better than pointer address as toString representation, which practically is useless. 对于上/下转换对象的情况,其行为仍优于指针地址作为toString表示,这实际上是没有用的。
Something like 就像是
// Returns the compile time 'ReflectionToStringBuilder.toString(foo)'
foo.tryToString()
What am I missing ? 我想念什么?
Replying a comment I found correct words to my question. 回复评论后,我发现我的问题的正确词。
Why do we have to hand code (/eclipse generated) toString/hash/equals which could have been done by Java compiler ? 为什么我们必须将Java编译器可以完成的代码(/ eclipse生成)传递给String / hash / equals?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.