小编tim*_*thy的帖子

如何从 bash 的历史记录中删除单个命令

经过一些在线搜索后,我发现以下命令应该从 bash 历史记录中删除单个条目:

$ history -d <number>
Run Code Online (Sandbox Code Playgroud)

假设我想从我的历史记录中删除这一行,因为我拼错了 git :

10003 gti add . && git commit -m
Run Code Online (Sandbox Code Playgroud)

当我执行以下命令时:

$ history -d 10003
Run Code Online (Sandbox Code Playgroud)

即使我重新启动终端,它仍然显示在我的历史记录中

所以我知道如何解决这个问题,因为我使用自动完成功能,有时尤其是在使用 git 时,它可能会变得有点混乱。

bash terminal command-line autocomplete windows-subsystem-for-linux

8
推荐指数
2
解决办法
8447
查看次数

什么是关键字"this"指的是它是否作为参数给出

我知道何时为字段和构造函数使用关键字"this"但我不确定它何时作为参数传递

    import javax.swing.*;
    import java.awt.event.*;

    public class SimpleGui implements ActionListener {
        JButton button;

    public static void main (String[] args) {
        SimpleGui gui = new SimpleGui();
        gui.go();
    }

    public void go() {
        JFrame frame = new JFrame();
        button = new JButton("click me");

        button.addActionListener(this);

        frame.getContentPane().add(button);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 300);
        frame.setVisible(true);
    }

    public void actionPerformed(ActionEvent event) {
        button.setText("I've been clicked!");
    }
}
Run Code Online (Sandbox Code Playgroud)

java this keyword

1
推荐指数
1
解决办法
85
查看次数

为什么这段 Java 代码隐式调用 toString() 方法?

为什么是输出?:球体 0

它以某种方式隐式调用 toString() 方法?这是如何运作的 ?

class BerylliumSphere {
    private static long counter = 0;
    private final long id = counter++;
    public String toString() { 
        return "Sphere " + id;
    }
}

public class Test {
    public static void main (String[] args) {
        BerylliumSphere spheres = new BerylliumSphere();
        System.out.println(spheres);
    }
}

// output: Sphere 0 
Run Code Online (Sandbox Code Playgroud)

java printing tostring implicit

-1
推荐指数
1
解决办法
1077
查看次数