Java – Do we have to do new on static classes

Do we have to do new on static classes… here is a solution to the problem.

Do we have to do new on static classes

While browsing the documentation, I read that some ViewHolder is a static class, but does it need to create a new one on the static class?
Did they do new in that example? But according to the concept new shouldn’t be done on a static class, right?

Solution

You can only construct a class in four ways:

  1. Use “new”
  2. Use Class.newInstance
  3. Use a method/factory that uses new internally to create a new instance
  4. If supported, use object.clone

1 and 3 are by far the most commonly used

Related Problems and Solutions