如何toString
使用interface的引用变量调用方法Test
,而没有toString
方法呢?
interface Test
{
void show();
String toHi();
}
class Demo implements Test
{
public void show(){
System.out.println("Show");
}
public String toString(){
return "Hello";
}
public String toHi(){
return "Hi";
}
public static void main(String[] args)
{
Test t=new Demo();
String s=t.toString();
System.out.println(s);
}
}
Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用旧的Facebook apprequests对话框实现,如:
Bundle parameters = new Bundle();
parameters.putString("message","invite friends message...");
parameters.putString("data","invite friends data...");
parameters.putString("title","invite friends dialog title...");
if (facebook != null){
facebook.dialog(getActivity(), "apprequests", parameters,
new Facebook.DialogListener() {
@Override
public void onComplete(Bundle values) {
// todo:
}
});
}
Run Code Online (Sandbox Code Playgroud)
我在facebook doc中找到了新的实现.应用邀请
appLinkUrl = "my app link...";
previewImageUrl = "my image url...";
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(appLinkUrl)
.setPreviewImageUrl(previewImageUrl)
.build();
AppInviteDialog.show(activity, content);
}
Run Code Online (Sandbox Code Playgroud)
这是邀请应用程序给朋友或任何其他方式的正确实现?如果是,那么我的消息和数据内容将放在哪里.
或者,如果我使用图形api请求,如:
String graphPath="/me/apprequests/";
GraphRequest request = GraphRequest.newGraphPathRequest(
accessToken, graphPath, graphCallback);
Bundle parameters = …
Run Code Online (Sandbox Code Playgroud) 当使用反射从另一个main方法调用Java类的main方法时,
Class thisClass = loader.loadClass(packClassName);
Method thisMethod = thisClass.getDeclaredMethod("main",String[].class);
thisMethod.invoke(null, new String[0]);
Run Code Online (Sandbox Code Playgroud)
我应该创建newInstance()还是简单地调用main(),因为它是静态的.
File f=new File("C:/");
File fList[] = f.listFiles();
Run Code Online (Sandbox Code Playgroud)
当我使用它时,它列出所有系统文件以及隐藏文件.
当我使用它在jTree中显示时,这会导致空指针异常,如下所示:
public void getList(DefaultMutableTreeNode node, File f) {
if(f.isDirectory()) {
DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
node.add(child);
File fList[] = f.listFiles();
for(int i = 0; i < fList.length; i++)
getList(child, fList[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
我应该怎么做,以便它不提供NullPointerException并在jTree中只显示非隐藏和非系统文件?
当我们在base以及派生类中声明方法为static并进行upcasting时,为什么它调用基类方法.
class Base
{
static void show(){
System.out.println("Base class....");
}
}
class Derive extends Base
{
static void show(){
System.out.println("Drive class....");
}//method hidding.....
public static void main(String[] args)
{
Base b= new Derive();
b.show();
}
}
Run Code Online (Sandbox Code Playgroud) java ×4
android ×1
facebook ×1
file-io ×1
filefilter ×1
interface ×1
jtree ×1
reflection ×1
swing ×1
upcasting ×1