使 returns 成为具有指定消息的 JOptionPane.showMessageDialog 的方法?

Make method that returns a JOptionPane.showMessageDialog with specified message?

我想问的是:

我一直在输入 JOptionPane.showMessageDialog,等等。所以,我想我可以做一个方法让它更短更容易,在这种情况下命名为 msgDialog().

public static String msgDialog(String message){
    return JOptionPane.showMessageDialog(null, message);
}

为什么这行不通? (错误:不能 return 无效结果。)

JOptionPane#showMessageDialog 没有 return 任何东西。因此,您可以改为这样做

public static void show(String s){
    JOptionPane.showMessageDialog(null, s);
}

尝试将方法类型更改为 void :

public static void msgDialog(String message){
        JOptionPane.showMessageDialog(null, message);
}