Home  >  Q&A  >  body text

java中返回一个对象,和输出对像的值,意义在哪儿

比如图上的return f;
这个有什么意义,

高洛峰高洛峰2743 days ago495

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:55:28

    This getInstance() method:

    1. Make members private and provide getter and setter methods uniformly to ensure safe access.

    2. Make the constructor private and replace it with an ordinary static method. There are three advantages over the constructor: a. The name can be more meaningful and clear at a glance; b. There is no need to construct a new instance every time it is called; c .Can return more flexible types, such as subclasses of this class, not necessarily this class. The fourth advantage, for type inference to simplify syntax, has been improved with the introduction of diamond syntax in Java 7. --"Effective Java" 2nd

    3. Simple factory mode and singleton mode can provide flexible instances, reduce the cost of creating instances, ensure consistent status, etc...

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:55:28

    f is the new factory() class. getinstance is an instantiation of the factory class. Call this method to get an instantiation of the class, and then you can call the internal method of the factory class

    reply
    0
  • Cancelreply