这被认为是反映到什么程度? [英] Is this considered reflection and to what degree?

查看:102
本文介绍了这被认为是反映到什么程度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序(JAVA)使用下面的code当了Android 1.6 SDK编译的是工作的罚款从android.provider.Contacts类:

I have an Android application (java) that was working fine when compiled with the Android 1.6 SDK using the following code from the android.provider.Contacts class:

Uri baseUri = Contacts.Phones.CONTENT_FILTER_URL;

在2.0 SDK出来了,android.provider.Contacts类是pciated和android.provider.ContactsContract替换德$ P $。为了得到一个程序工作在两个1.6和2.0,我在1.6编译如下变化:

When the 2.0 SDK came out, the android.provider.Contacts class was depreciated and replaced with android.provider.ContactsContract. In order to get one program to work on both 1.6 and 2.0, I compiled under 1.6 with the following change:

Uri baseUri = Contacts.Phones.CONTENT_FILTER_URL;
…
try {
    Class<?> c = Class.forName("android.provider.ContactsContract$PhoneLookup");
    baseUri = (Uri) c.getField("CONTENT_FILTER_URI").get(baseUri);
} 
    catch (Exception e) {           
}

由于我是根据1.6编译,我不能导入android.provider.ContactsContract,因为它是一类已知的只有2.0。这被认为是反映到什么程度?

Since I was compiling under 1.6, I could not import android.provider.ContactsContract since it is a class known only to 2.0. Is this considered reflection and to what degree?

添加注释:阅读Java编程语言(这是我应该做的第一)的反思一章后,我主要是现在明白了,你可以与反思,但一个简明的定义做反思是不容易得到。您的回答有助于澄清什么原因促使我的问题 - 一旦一个类已经有所体现,并使用反射创建类的实例,您可以用实例进行交互,就好像类是new'ed

Added Comment: After reading the "Reflection" chapter of "The Java Programming Language" (which I should have done first), I mostly now understand what you can do with reflection but a concise definition of reflection is not easy to come by. Your answers have helped to clarify what prompted my question - that once a class has been reflected on, and an instance of the class created using reflection, you can interact with the instance as if the class was new'ed.

下面是我的微薄尝试一个简明的定义是远远不够完善,我相信我会需要修改,​​因为我了解更多内容:

Here is my meager attempt at a concise definition that is far from perfect and I am sure I will need to revise as I learn more:

反思是间接的,动态的查询,包含在java.lang.reflect中或需要使用完全合格的字符串名称最初访问类,类或包中的类操作或使用类对象类对象调用

Reflection is the indirect, dynamic inquiry, manipulation or invocation of class objects using class objects contained in java.lang.reflect or the Class or Package classes that requires initially accessing the class using a fully qualified string name.

推荐答案

我相信是的 Java反射更在Android上反射的多项版本兼容性)。我不知道你所说的到什么程度的意思;它仅仅是。

I believe that is the very definition of Java reflection (more on Android reflection for multiple-version compatibility). I'm not sure what you mean by "to what degree"; it just is.

这篇关于这被认为是反映到什么程度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆