The problem of static import of classes in the same directory in java

problem description

in the process of learning java static import, the myMath class and static_import class are written in the same folder . The static_import class invokes the static methods of the myMath class directly by statically importing the myMath class.

myMath.java

public class myMath{
    public static int div(int x, int y) throws Exception{
        System.out.println("===start===");
        int result = 0;
        try{
            result = x / y;
        }catch(Exception e){
            throw e;
        }finally{
            System.out.println("===end===");
        }
        return result;
    }
    public static int add(int x, int y){
        return x + y;
    }
}

static_import.java

import static myMath.*;
public class static_import{
    public static void main(String args[]){
        System.out.println("Add operation:" + add(10,20));
        try{
            System.out.println("divide operation: " + div(10,2));
        }catch(Exception e){
            e.printStackTrace();
        }
        
    }
}

the error prompt is shown in the following figure:

clipboard.png
how do I use import static to import the static methods of the myMath class into the static_import class when the myMath.java and static_import classes to be imported are in the same folder?

May.12,2021

import static xxx.xx.xxx.*


I've written it before, but it doesn't make any sense later. If Javac is so good, what's the matter with ide?

Menu