起初,抱歉我的英语不好.我有代码片段:
long x = 9223372036854775807L;
double f = x;
Console.WriteLine(x);
Console.WriteLine(f);
Run Code Online (Sandbox Code Playgroud)
输出是:
9223372036854775807
9,22337203685478E+18
Run Code Online (Sandbox Code Playgroud)
编译和执行此代码时,我没有收到任何错误.在将Long转换为Double时,我们的精度会下降.为什么C#在这种情况下不需要显式转换?
谢谢大家.
我已经创建了简单的代码片段来演示JAVA的一些奇怪的东西.
public class Start extends JFrame {
public static JFrame mainFrame;
public static void main(String[] args) {
JFrame f = new JFrame();
mainFrame = f;
f.setSize(400, 400);
Action btn_action = new AbstractAction() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("test");
JDialog d = new JDialog(mainFrame, "Test Dialog", true);
d.setSize(200, 200);
d.setLocationRelativeTo(null);
JTextField text = new JTextField();
d.add(text);
d.setVisible(true);
}
};
JButton btn = new JButton(btn_action);
btn.setText("Click me");
KeyStroke btnShortcut = KeyStroke.getKeyStroke(KeyEvent.VK_1, 0);
btn.getActionMap().put("btn_click", btn_action);
btn.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(btnShortcut, "btn_click");
f.add(btn);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);
} …Run Code Online (Sandbox Code Playgroud)