1

我正在尝试使用Reflections 库来获取使用特定 Java annotation 注释的所有类。

我在 .gradle 文件中包含了 Reflections 库:

compile 'org.reflections:reflections:0.9.10'

但是,该库不适用于我在 Android 上。我没有从 no 和 中得到任何getSubTypesOf点击getTypesAnnotatedWith

我的实施有什么问题吗?

package sample.anotherapp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;

import java.util.Set;

@Deprecated
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Reflections reflections = new Reflections("sample.anotherapp", new SubTypesScanner(false), new TypeAnnotationsScanner());

        Set<Class<? extends AppCompatActivity>> subTypesOf = reflections. getSubTypesOf(AppCompatActivity.class);
        int size = subTypesOf.size();

        Set<Class<?>> annotated = reflections. getTypesAnnotatedWith(Deprecated.class);
        size = annotated.size();
    }
}

所以问题可能是...... Google-reflections 库是否适用于 Dalvik

4

0 回答 0