Why can't I import static java.lang.System.out.println?

后端 未结 7 1129
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 09:30

It seems strange that I can\'t import static java.lang.System.out.println, when I can import static java.lang.Math.abs. Is there some reason behind this or am I doing somet

相关标签:
7条回答
  • 2020-12-05 10:17

    My solution

    package example.tools;
    
    public class ShowMe {
        /*public static void print(String arg) {
           System.out.println(arg);
        }*/
        // or better as ceving's example
        public static<T> void print(T arg) {
            System.out.println(arg);
        }
    }
    

    In another class

    import static example.tools.ShowMe.*;
        public class Flower {
            Flower() {
                print("Rose");
            }
        }
    
    0 讨论(0)
提交回复
热议问题