public class Animal {
public void eat() {}
}
public class Dog extends Animal {
public void eat() {}
public void main(String[] args) {
Animal animal = new Animal();
Dog dog = (Dog) animal;
}
}
Run Code Online (Sandbox Code Playgroud)
赋值Dog dog = (Dog) animal;
不会生成编译错误,但在运行时会生成一个ClassCastException
.为什么编译器无法检测到此错误?
FileReader rd=new FileReader("new.mp4");
FileWriter wr=new FileWriter("output.mp4");
int ch;
while((ch=rd.read())!=-1)
wr.write(ch);
wr.flush();
wr.close();
Run Code Online (Sandbox Code Playgroud)
当我使用FileReader
和FileWriter
读取和写入mp4文件时,output.mp4
文件无法很好地呈现.但是当我使用它时FileInputStream
,FileOutputStream
它运作良好.
那么我可以得出结论FileReader
,FileWriter
仅用于阅读和撰写文本吗?
这里他们是同一个实例:
Integer integer1 = 127;
Integer integer2 = 127;
System.out.println(integer1 == integer2); // outputs "true"
Run Code Online (Sandbox Code Playgroud)
但在这里他们是不同的实例:
Integer integer1 = 128;
Integer integer2 = 128;
System.out.println(integer1 == integer2); // outputs "false"
Run Code Online (Sandbox Code Playgroud)
为什么包装器对象仅在值127内共享同一实例?
为什么必须在构造函数完成之前初始化最终变量?
public class Ex
{
final int q;
}
Run Code Online (Sandbox Code Playgroud)
当我编译这段代码时,我得到这样的错误
错误:变量q可能尚未初始化
为什么不switch
表达允许long
,float
,double
或boolean
在Java中值?为什么只允许 int
(和那些自动升级的int
)允许?
class Coffee{
enum CoffeeSize{BIG,HUGE,OVERWHELMING}
CoffeeSize size;
}
class CoffeeTest{
public static void main(String[] args)
{
Coffee drink=new Coffee();
drink.size=Coffee.CoffeeSize.BIG;
}
}
Run Code Online (Sandbox Code Playgroud)
Coffee.CoffeeSize.BIG
:我可以CoffeeSize
使用类名Coffee
.当我认为枚举类型是隐式静态时,我是否正确?
ParseImageView是否在Android中缓存ParseFile.如果它缓存parseFile,我如何在我的Android设备中找到这些文件的路径.
ParseImageView imageView = (ParseImageView) findViewById(android.R.id.icon);
// The placeholder will be used before and during the fetch, to be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(R.drawable.placeholder));
imageView.setParseFile(file);
imageView.loadInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length + ", or exception: " + e.getMessage());
}
});
Run Code Online (Sandbox Code Playgroud) 如何使用文本制作按钮,操作栏中的图像如下所示.
是否可以使用Inbuilt android按钮或图像按钮在操作栏中执行如下操作.
我正在使用appcompat来使用操作栏.
在InAppBilling V3的google文档中,他们使用IInAppBillingService进行购买.检查以下网址.
http://developer.android.com/google/play/billing/billing_integrate.html
Bundle buyIntentBundle = mService.getBuyIntent(3,getPackageName(),sku,"inapp","bGoa + V7g/yqDXvKRqq + JTFn4uQZbPiQJo4pf9RzJ");
但是在随着SDK发布的Trivial Example中,他们使用IABHelper进行购买.
我很困惑,比如IABHelper是V2还是IInAppBillingService是V3.
因为你无法通过IABHelper获得可用的SKU详细信息.但是通过IInAppBillingService,它是可能的
Bundle skuDetails = mService.getSkuDetails(3,getPackageName(),"inapp",querySkus);
哪一个是最新版本?