Best practice for returning multiple values in Java?

前端 未结 7 1177
走了就别回头了
走了就别回头了 2020-12-05 17:31

Today I\'ve added a extra security check behind my login forms, to slow down brute force attacks. I\'ve got multiple login forms and made a nice easy to call function that d

相关标签:
7条回答
  • 2020-12-05 18:34

    I can't really think of a better, cleaner and more object-oriented way of returning multiple values from a function than encapsulating them in a class.

    Ideally, the multiple values you want to return are conceptually all part of the same class, so it makes sense to group them this way; if they don't, then you should probably decompose your function in some smaller functions that return each of the values you need outside of the function itself.

    As far as I can tell, some IDEs also have facilities to help encapsulating multiple values in a class: for instance, Eclipse has Refactor --> Extract class...

    0 讨论(0)
提交回复
热议问题