以下是代码段:
public abstract class MyAbstractClass {
public abstract void a();
public abstract void b();
}
public class Foo extends MyAbstractClass {
public void a() {
System.out.println("hello");
}
public void b(){
System.out.println("bye");
}
}
public class Bar extends MyAbstractClass {
public void a() {
System.out.println("hello");
}
public void delta() {
System.out.println("gamma");
}
}
Run Code Online (Sandbox Code Playgroud)
我有几个问题:
问题1: - 我应该在abstract课堂上实现所有方法吗?
问题2: - 实现类可以有自己的方法吗?
AlertDialog当我添加消息时,有人知道为什么不显示项目列表.setMessage()吗?将显示负面和正面按钮,但不会显示列表.当我删除所有行的行.setMessage().
这是我的代码:
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this.getActivity());
myAlertDialog.setTitle("Options");
myAlertDialog.setMessage("Choose a color.");
CharSequence[] items = {"RED", "BLUE", "GREEN" };
myAlertDialog.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do stuff
}
});
myAlertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do stuff
}
});
myAlertDialog.setPositiveButton("YES",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do stuff
}
});
myAlertDialog.create();
myAlertDialog.show();
Run Code Online (Sandbox Code Playgroud) 我想在HTML 5中裁剪视频.
<video id="glass" width="640" height="360" autoplay>
<source src="invisible-glass-fill.mp4" type="video/mp4">
</video>
Run Code Online (Sandbox Code Playgroud)
视频的分辨率为640x360,但是当我将width属性设置为200时,视频将重新缩放(保留宽高比).如何通过HTML或Javascript裁剪视频(切断,比如左右两侧220像素)?是否可以通过视频编辑软件裁剪视频?
为什么注释@SafeVarargs不能应用于非最终实例方法?
我正在Java应用程序中尝试这个简单的计算:
System.out.println("b=" + (1 - 7 / 10));
Run Code Online (Sandbox Code Playgroud)
显然我想要b=0.3输出,但这就是我得到的b=1.
什么?!为什么会这样?
如果我做:
System.out.println("b=" + (1 - 0.7));
Run Code Online (Sandbox Code Playgroud)
我得到了正确的结果b=0.3.
这里出了什么问题?
我有两个Java接口和一个实现类.
(我已经使用Eclipse直接运行程序,并且我没有尝试通过从命令行显式编译来检查任何编译器警告等.)
为什么他们没有问题?为什么Java允许这样做,即使它满足两个接口的"契约"但是在实现类时产生歧义?
更新了示例.
public interface CassettePlayer {
void play();
}
public interface DVDPlayer {
void play();
}
public class CarPlayer implements CassettePlayer,DVDPlayer{
@Override
public void play() {
System.out.println("This plays DVD, screw you Cassette !");
}
public static void main(String args[]) {
CarPlayer cp = new CarPlayer();
cp.play();
CassettePlayer firstInterface = new CarPlayer();
firstInterface.play();
DVDPlayer secondInterface = new CarPlayer();
secondInterface.play();
}
}
Run Code Online (Sandbox Code Playgroud) 我是Java的新手,在学习的时候,我发现了一个String不可变的事实.当我阅读其背后的原因时,出现了一些原因,例如性能提升,因为它的值无法修改,并且可以由多个线程共享.这些理由我明白了.
但我不知道它与安全性有什么关系.如何String在Java安全性中提供不可变的帮助?
请帮助我理解.提前致谢.
我一直试图找出原因,但我不能.有谁能够帮我?
请看下面的例子.
float f = 125.32f;
System.out.println("value of f = " + f);
double d = (double) 125.32f;
System.out.println("value of d = " + d);
Run Code Online (Sandbox Code Playgroud)
这是输出:
值f = 125.32
值d = 125.31999969482422
ANTLRWorks2中的TestDriver似乎有点挑剔,它什么时候会接受没有和明确的语法EOF,什么时候不接受.ANTLR4入门指南中的Hello语法不会在任何地方使用,因此我推断如果可能的话,最好避免显式.EOFEOF
使用的最佳做法是EOF什么?你什么时候需要它?
Java 8并行流如何在使用子句中的抛出异常上运行,例如在forEach处理中?例如,以下代码:
final AtomicBoolean throwException = new AtomicBoolean(true);
IntStream.range(0, 1000)
.parallel()
.forEach(i -> {
// Throw only on one of the threads.
if (throwException.compareAndSet(true, false)) {
throw new RuntimeException("One of the tasks threw an exception. Index: " + i);
});
Run Code Online (Sandbox Code Playgroud)
它会立即停止处理元素吗?是否等待已经启动的元素完成?是否等待所有流完成?抛出异常后是否开始处理流元素?
什么时候回来?异常后立即?毕竟/部分元素是由消费者处理的?
在并行流引发异常后,是否继续处理元素?(发现这种情况发生的情况).
这里有一般规则吗?
编辑(15-11-2016)
试图确定并行流是否提前返回,我发现它不是确定的:
@Test
public void testParallelStreamWithException() {
AtomicInteger overallCount = new AtomicInteger(0);
AtomicInteger afterExceptionCount = new AtomicInteger(0);
AtomicBoolean throwException = new AtomicBoolean(true);
try {
IntStream.range(0, 1000)
.parallel()
.forEach(i -> {
overallCount.incrementAndGet();
afterExceptionCount.incrementAndGet();
try …Run Code Online (Sandbox Code Playgroud) parallel-processing exception-handling exception java-8 java-stream
java ×6
android ×1
antlr ×1
antlrworks ×1
division ×1
double ×1
exception ×1
generics ×1
html5 ×1
html5-video ×1
ieee-754 ×1
interface ×1
java-8 ×1
java-stream ×1
javascript ×1
jquery ×1
oop ×1
precision ×1
security ×1
string ×1