我需要一个建议
class A{
B b;
}
Class B{
P String something();
}
Run Code Online (Sandbox Code Playgroud)
在
class test{
B b = new B();
b.something();
}
something()
Run Code Online (Sandbox Code Playgroud)
必须返回cal-lee类的名称,如果有人叫我(按名字)我应该知道他的名字.
我想创建一个if语句来检查哪个方法调用了辅助方法.
我会用伪代码写出我想要的东西,这样你就可以看出我的意思了.
public static void methodOne() {
methodToCall();
}
public static void methodTwo() {
methodToCall();
}
public static void methodThree() {
methodToCall();
}
public static void methodToCall() {
if (methodOne made the call == true) {
execute this
} else if (methodTwo made the call == true){
execute this
} else if (methodThree made the call == true){
execute this
} else {
System.out.println("How did you get here?");
}
}
Run Code Online (Sandbox Code Playgroud)
这是关于它的要点.我想要一个简单的检查,看看哪个方法进行了调用,这样我就可以选择哪个操作与调用相关.
这可能吗?
如果不可能,是否有解决方法?
我想知道哪个方法或哪个类称为构造函数MyClass.
public class MyClass
{
private static int instCount = 0;
public MyClass()
{
instCount++;
System.out.println("MyClass Konstruktor wurde aufgerufen! [" + instCount + "]");
}
}
Run Code Online (Sandbox Code Playgroud)