public Method[] getDeclaredMethods() throws SecurityException
Run Code Online (Sandbox Code Playgroud)
有如下文件.
/**
*
* Returns an array containing {@code Method} objects reflecting all the
* declared methods of the class or interface represented by this {@code
* Class} object, including public, protected, default (package)
* access, and private methods, but excluding inherited methods.
<p> If this {@code Class} object represents a type that has multiple
* declared methods with the same name and parameter types, but different
* return types, then the returned array has …Run Code Online (Sandbox Code Playgroud) 我有来自两家公司asoft和bsoft的代码.我也无法改变.这是我的情况的简化版本,我非常确定有足够的信息来查找导致问题的原因.
bsoft提供IGang,代表一个可以与其他帮派作战的团伙.
package bsoft;
public interface IGang {
/** @return negative, 0, or positive, respectively
* if this gang is weaker than, equal to, or stronger
* than the other
*/
public int compareTo(IGang g);
public int getStrength();
public String getName();
public void attack(IGang g);
public void weaken(int amount);
}
Run Code Online (Sandbox Code Playgroud)
asoft提供GangWar,允许IGangs战斗:
package asoft;
import java.util.*;
import bsoft.*;
/** An `IGang` ordered by identity (name) */
public interface ComparableGang extends IGang, Comparable<IGang> {}
package asoft; …Run Code Online (Sandbox Code Playgroud) 我是一名Java开发人员,我一直在学习C++.我最近在C++中进入了"致命的死亡钻石"并研究了这个问题是否可能在Java中出现.在Do界面解决"致命的死亡钻石"问题?, 我找到了这个:
Java 8为方法搞砸了; 现在,接口可以声明默认方法和静态方法实现.这将大量的死亡钻石问题带入语言中.
我想知道是否有人能够扩展Java 8为DDD引入的问题.
我有2个类,例如A和B.
这些类有几个具有相同名称的getter/setter方法.
现在在代码中我执行以下操作:
if(obj.getClassName().equals(A.class.getName())){
A a = (A) obj;
String result = a.getInfo();
}
else if(obj.getClassName().equals(B.class.getName())){
B a = (B) obj;
String result = a.getInfo();
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法调用getInfo避免if语句.
注意:我无法重构类以使用继承或其他东西.
我只是感兴趣,如果在java中有一个技巧,以避免if语句.
我有以下 2 个接口。
public interface I1 {
public void show();
}
Run Code Online (Sandbox Code Playgroud)
另一个
public interface I2 {
public void show();
}
Run Code Online (Sandbox Code Playgroud)
我们有一个类同时实现了两者。
public class Main implements I1,I2 {
@Override
public void show() {
System.out.println("Hello I am mahima");
}
Run Code Online (Sandbox Code Playgroud)
我运行了程序,没有编译或运行时错误。我如何找到这里调用的接口方法?有没有办法找到它?
这个问题是在第一轮亚马逊面试中被问到的。