我在第三方设计的设计很差JAR,我需要访问其中一个私有字段.例如,为什么我需要选择私人领域是否有必要?
class IWasDesignedPoorly {
private Hashtable stuffIWant;
}
IWasDesignedPoorly obj = ...;
Run Code Online (Sandbox Code Playgroud)
我如何使用反射来获得价值stuffIWant?
当我尝试为来电创建自定义屏幕时,我正在尝试以编程方式接听来电.我使用以下代码但它在Android 5.0中不起作用.
// Simulate a press of the headset button to pick up the call
Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");
// froyo and beyond trigger on buttonUp instead of buttonDown
Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
Run Code Online (Sandbox Code Playgroud) 如何动态循环遍历java中的类属性.
例如:
public class MyClass{
private type1 att1;
private type2 att2;
...
public void function(){
for(var in MyClass.Attributes){
System.out.println(var.class);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这在Java中可能吗?
是否有一个库将以递归方式转储/打印对象属性?我正在寻找类似于Firebug中的console.dir()函数的东西.
我知道commons-lang ReflectionToStringBuilder但它没有递归到一个对象.即,如果我运行以下内容:
public class ToString {
public static void main(String [] args) {
System.out.println(ReflectionToStringBuilder.toString(new Outer(), ToStringStyle.MULTI_LINE_STYLE));
}
private static class Outer {
private int intValue = 5;
private Inner innerValue = new Inner();
}
private static class Inner {
private String stringValue = "foo";
}
}
Run Code Online (Sandbox Code Playgroud)
我收到:
ToString $ Outer @ 1b67f74 [intValue = 5
innerValue = ToString $ Inner @ 530daa]
我意识到在我的例子中,我可以覆盖Inner的toString()方法,但在现实世界中,我正在处理我无法修改的外部对象.
我看到很多问题,在Android中以编程方式结束呼叫是不可能的.同时,我在googleplay市场上看到很多拨号器应用程序,您可以在其中激活呼叫并将其丢弃.他们是如何工作的?
编辑:我读过我的应用程序必须是系统应用程序的地方.那么如何制作系统,系统和用户应用程序之间有什么区别?
Void类是一个不可实例化的占位符类,用于保存对表示Java关键字void的Class对象的引用.
但构造函数很简单:
private Void() {}
Run Code Online (Sandbox Code Playgroud)
这段代码实例化了一个Void:
Constructor<Void> c = Void.class.getDeclaredConstructor();
c.setAccessible(true);
Void v = c.newInstance(); // Hello sailor
Run Code Online (Sandbox Code Playgroud)
所以Void是不是不可实例.
是否有办法让Void真正无法实现?
春天的定义ApplicationContext非常模糊,我几乎完成了整本教程,但仍然无法理解它的ApplicationContext立场.
根据Spring API,ApplicationContext是:
用于为应用程序提供配置的中央接口.这在应用程序运行时是只读的,但如果实现支持,则可以重新加载.
用于访问Spring bean容器的根接口.这是bean容器的基本客户端视图.
从上面,我的问题是:
1)我一直看到书中提到的"容器",容器是指什么?一个容器是否意味着一个java进程?或一个容器是指一个ApplicationContext对象?
2)如果我ApplicationContext在一个java应用程序中实例化两个(都在main体内),这两个接口是一个中央容器吗?还是两个单独的实例?看下面的代码,context1和之间有什么区别context2?如果有一个Singleton Beans.xml,它是由context1和context2两个独立的实例或同一个实例调用的?
ApplicationContext context1 = new ClassPathXmlApplicationContext("Beans.xml");
ApplicationContext context2 = new ClassPathXmlApplicationContext("Beans.xml");
Run Code Online (Sandbox Code Playgroud) 它需要一种方法来调用函数,其名称存储在类似于eval的字符串中.你能帮我吗?
java ×7
reflection ×4
android ×2
phone-call ×2
attributes ×1
c++ ×1
class ×1
dump ×1
eval ×1
field ×1
loops ×1
private ×1
properties ×1
spring ×1
tostring ×1
void ×1