简体   繁体   English

这段代码意味着什么?

[英]What does this block of code mean?

What does the second block below run() in the anonymous class new Runnable() { that has no identifier or declaration preceding it mean: 匿名类new Runnable(){之前没有标识符或声明的第二个块下面的run()是什么意思:

        public BackgroundThread(final Runnable runnable)
        {
            super(new Runnable() {

                final Runnable val$runnable;

                public void run()
                {
                    Process.setThreadPriority(10);
                    runnable.run();
                }


                {
                    runnable = runnable1;
                    super();
                }
            });
        }

Edit: yes it is decompiled code. 编辑:是的,它是反编译的代码。

It's an instance initializer - called as part of the constructor. 它是一个实例初始化程序 - 作为构造函数的一部分调用。 In an anonymous inner class, you can't explicitly declare a constructor, so instance initializers are sometimes used instead. 在匿名内部类中,您无法显式声明构造函数,因此有时会使用实例初始值设定项。 In this case it's pretty pointless, as the run method could just use runnable directly - it would still be captured at the same time. 在这种情况下,它是毫无意义的,因为run方法可以直接使用runnable - 它仍然可以同时捕获。

(This code doesn't look like it's complete or valid, actually - given that the instance initializer mentions runnable1 which doesn't appear anywhere else. I'd also not expect the instance initializer to include a super() call. Is this possibly decompiled code?) (实际上,这个代码看起来并不完整或有效 - 假设实例初始化程序提到了runnable1 ,它没有出现在其他任何地方。我也不希望实例初始化程序包含一个super()调用。这可能是反编译代码?)

It's an initialization block. 这是一个初始化块。 It gets compiled into every constructor. 它被编译到每个构造函数中。

See "Initializing Instance Members" in the tutorial . 请参阅教程中的“初始化实例成员”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM