请考虑以下界面:
package hf;
public interface BadInterface
{
void meth() throws Exception;
}
Run Code Online (Sandbox Code Playgroud)
这由以下类实现:
package hf;
public class apples implements BadInterface
{
public static void main(String[] args)
{
new apples().meth();
}
public void meth()
{
System.out.println("Ding dong meth.");
}
}
Run Code Online (Sandbox Code Playgroud)
尽管meth()是抛出异常的方法,但方法meth()的调用者不必处理或声明异常,但程序运行成功.为什么会这样?它是否违反了规则,即每当您调用抛出异常的方法时,您需要捕获异常或声明您自己抛出异常?
我在这里阅读 git 教程,其中提到:
\n\n\n\n\n不要\xe2\x80\x99t 在其他开发人员从中拉取的公开可见分支上使用 git Reset,因为这会强制其他开发人员进行不必要的合并来清理历史记录
\n
我不明白问题是什么。如果我有一个公共分支,有 4 个提交,A->B->C->D。D 是最新提交。如果我硬重置回 B。然后,对于已经获取此分支的其他开发人员,当他们再次执行 git fetch 时,他们会看到它们比远程提前了 2 个提交,因此他们重置回B和都好对吧?或者我错过了什么?
\n该程序使球从左上角到右下角滑动并起作用.但是,如果我要改变界限
frame.getContentPane().add(ball);
Run Code Online (Sandbox Code Playgroud)
从当前位置到for循环之后,为什么球不会出现在框架上.我同意球不应再移动,因为在我将球添加到JFrame之前,所有在for循环中完成的移动都会发生,但是我不明白为什么当我最终将球出现在屏幕上时将其添加到框架中.这是工作程序的代码,如果你将上面提到的行移到for循环之后,球就不再出现了
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Animate
{
private JFrame frame;
private int x,y;
public static void main(String args[])
{
Animate ballRoll = new Animate();
ballRoll.go();
}
public void go()
{
frame = new JFrame();
frame.setSize(500,500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyRoll ball = new MyRoll();
frame.getContentPane().add(ball);
for(x = 5;x<=350;x++)
{
y=x;
try
{
Thread.sleep(50);
}
catch(Exception e)
{
System.out.println("dsfsd");
}
ball.repaint();
}
}
class MyRoll extends JPanel
{
public void paintComponent(Graphics g)
{
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getWidth(), …Run Code Online (Sandbox Code Playgroud) 第1类:
package hf;
public class apples
{
public static void main(String[] args)
{
Good good = new Good();
good.method();
}
}
Run Code Online (Sandbox Code Playgroud)
第2类:
package hf;
public class Goodie extends NullPointerException
{
}
Run Code Online (Sandbox Code Playgroud)
第3类:
package hf;
public class Good
{
public void method() throws Goodie
{
System.out.println("Goodmethod");
throw new Goodie();
}
}
Run Code Online (Sandbox Code Playgroud)
我没有使用任何的try/catch块捕获NullPointerException异常(延伸的RuntimeException)当我打电话的1类good.method()当我运行程序时引发,在Eclipse控制台表明该程序仍在运行因为它不会显示在控制台框的顶部,就像程序执行结束时一样.
为什么程序仍在运行?
如何在不按红色停止按钮的情况下暂停程序执行?
当我将以下代码添加到layout.xml文件时,加载布局时应用程序崩溃。
码:
<android.support.design.button.MaterialButton
android:id="@+id/b_p_add"
android:layout_width="143dp"
android:layout_height="38dp"
android:layout_below="@+id/et_p_addl_notes"
android:layout_centerHorizontal="true"
android:layout_marginTop="43dp" />
Run Code Online (Sandbox Code Playgroud)
我检查了我的应用程序gradle文件并发现
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
Run Code Online (Sandbox Code Playgroud)
因此,存在所需的设计,支持和appcompat依赖项。
注意:除上述代码外,未添加其他代码,即,如果我未在XML中添加“材质”按钮,则该应用程序运行正常,如果在XML中添加了“材质”按钮,则该应用程序将崩溃。
user-interface android button material-design android-design-library
如果我要编写一个创建线程的主类,那么该类创建的线程是否可能比创建它的类的main()更长.
在某种程度上似乎可能因为,我可以使新创建的线程休眠一小时,因此新堆栈进入阻塞状态,使原始主堆栈可以执行,主堆栈执行并且没有其他任何操作,新堆栈仍处于阻塞状态.
但另一方面,在Java中有这样的陈述,一切都以main()方法开始和结束.
请告诉我哪一个是正确的