search

Home  >  Q&A  >  body text

java里自定义类重载ClassLoader有什么用?

java里自定义类重载有什么用?

PHP中文网PHP中文网2802 days ago669

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-18 10:50:49

    It should be convenient to use. The parameters passed in the function are different but the function is the same. I think it's a habit and style. You don’t have to do this either

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:50:49

    In fact, in my opinion, there are only 4 situations for all functions.
    Overloading is for contextual semantics:
    For example:

    void say(String name, Integer age)
    
    void say(String name)
    

    Of course you will say that you can define a wide range of input parameter lists to include the possibility of all subsets;

    For example

    void say(String name, Integer age, String address){
        if(name!=null){
            ....
        }
        if(age!=null){
            ...
        }
        ...
    }
    
    那么使用的时候反而增大了操作量比如
    
    say("张三",null,null);

    reply
    0
  • Cancelreply