Java异常堆栈跟踪中出现了”$8″,这是什么意思?

huangapple go评论131阅读模式
英文:

Java exception stacktrace has "$8", what does this mean?

问题

这不是我第一次看到异常消息,但我对堆栈跟踪中的特殊字符含义很好奇。我在Android中使用Java,此异常在类名旁边显示了一个$8,然后显示了发生异常的方法名。

我进行了研究,但未能找到有关其含义的任何信息。以下是堆栈跟踪和我所指的$8

java.lang.Exception: 错误,服务器响应 400
    at cb.cheneytracker.service.callers.ServerCaller$8.onResponse(ServerCaller.java:858)
    at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1$1.run(DefaultCallAdapterFactory.java:83)

更准确地说,由于我因为“需要详细信息或清晰度”而受到了投票下降。在上面的异常堆栈跟踪中,$代表什么?我看到了$8$1$1,这些是什么意思?

英文:

So this is not the first time I see exception messages but I'm curious as to what the special characters mean in the stacktrace. I'm using Java in Android and this exception shows a $8 right next to the class name then the method name where the exception took place.

I was researching but was not able to find any information on what it means. Below is the stacktrace and the $8 I'm referring to.

java.lang.Exception: Error, server response 400
    at cb.cheneytracker.service.callers.ServerCaller$8.onResponse(ServerCaller.java:858)
    at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1$1.run(DefaultCallAdapterFactory.java:83)

So to be more precise, since i'm getting down-voted for "needs detail or clarity". What does $ mean in the exception stack trace above. I see $8 and $1$1, what do these mean?

答案1

得分: 2

以下是翻译好的部分:

这是匿名类的自动生成名称,它是“8”,因为容器类中至少有8个匿名类,您可以在以下示例中看到其效果:

    interface Test {
        void doSomething();
    }
    public static Test createTest() {
        return new Test() {
            @Override
            public void doSomething() {
                System.out.println("我在忙...");
            }
        };
    }
    public static Test createAnotherTest() {
        return new Test() {
            @Override
            public void doSomething() {
                System.out.println("好的");
            }
        };
    }
    public static void main(String[] args) {
        Test t = createTest();
        System.out.println(t.getClass().getName());

        t = createAnotherTest();
        System.out.println(t.getClass().getName());
    }
英文:

It is the auto generated name for anonymous class, it is 8 because there are at least 8 anonymous class in the container class, you can see it in action here:


    interface Test {
        void doSomething();
    }
    public static Test createTest() {
        return new Test() {
            @Override
            public void doSomething() {
                System.out.println("I'm busy...");
            }
        };
    }
    public static Test createAnotherTest() {
        return new Test() {
            @Override
            public void doSomething() {
                System.out.println("Ok");
            }
        };
    }
    public static void main(String[] args) {
        Test t = createTest();
        System.out.println(t.getClass().getName());

        t = createAnotherTest();
        System.out.println(t.getClass().getName());
    }

答案2

得分: 1

我知道,这是编译器自动生成的匿名类的名称。

英文:

As I know, it is a name of anonymous class that compiler automatically generated

huangapple
  • 本文由 发表于 2020年10月10日 02:18:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/64285343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定