How to do call by reference in Java?

前端 未结 12 643
悲&欢浪女
悲&欢浪女 2021-01-30 17:36

Since Java doesnt support pointers, How is it possible to call a function by reference in Java like we do in C and C++??

12条回答
  •  无人及你
    2021-01-30 18:09

    Usually in java this is solved by using interfaces:

    Collections.sort(list, new Comparator() {
    
      @Override
      public int compareTo(Object o1, Object o2) {
      /// code
      }
    
    });
    

提交回复
热议问题