相关疑难解决方法(0)

我怎么知道打电话给我班级的班级名字?我不需要被叫者在其班级提供任何信息

我需要一个建议

 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类的名称,如果有人叫我(按名字)我应该知道他的名字.

java

2
推荐指数
1
解决办法
132
查看次数

在Java中调用方法的调用者

只是想知道,你如何找出调用另一种方法的方法的名称?我想使用Method类.

java

2
推荐指数
1
解决办法
130
查看次数

我可以使用If语句来检查调用哪个方法吗?

我想创建一个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)

这是关于它的要点.我想要一个简单的检查,看看哪个方法进行了调用,这样我就可以选择哪个操作与调用相关.

这可能吗?

如果不可能,是否有解决方法?

java methods if-statement

1
推荐指数
1
解决办法
1803
查看次数

哪个Java方法称为我的构造函数?

我想知道哪个方法或哪个类称为构造函数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)

java methods constructor class call

0
推荐指数
1
解决办法
1497
查看次数

标签 统计

java ×4

methods ×2

call ×1

class ×1

constructor ×1

if-statement ×1