位置: 首頁 > 計算機 > java語言

java利用反射實現動態代理實現程式碼

2014-11-16 java語言

複製程式碼 程式碼如下:

package ;

import d;

import od;

import fier;

import er;

/**

*

*

Title:

*

Description: 反射

*

Company: 點滴工作室

* @version 2.0

*

*/

public class ReflectUtil {

private static final Logger log = ogger(s);

@SuppressWarnings({ "rawtypes", "unchecked" })

public static void setFieldValue(Object target, String fname, Class ftype,

Object fvalue) {

if (target == null

|| fname == null

|| ""ls(fname)

|| (fvalue != null && !signableFrom(lass()))) {

return;

}

Class clazz = lass();

try {

Method method = eclaredMethod("set"

+ perCase(At(0))

+ tring(1), ftype);

if (!blic(odifiers())) {

ccessible(true);

}

ke(target, fvalue);

} catch (Exception me) {

if (bugEnabled()) {

// g("me異常-------->:"+me);

}

try {

Field field = eclaredField(fname);

if (!blic(odifiers())) {

ccessible(true);

}

(target, fvalue);

} catch (Exception fe) {

if (bugEnabled()) {

g("fe----------->"+fe);

}

}

}

}

}

標籤:JAVA 代理 程式碼
2015-09-20
2016-10-03
2016-08-22
2014-11-16
2014-11-18
2014-12-11
2014-11-18
2016-10-21
2016-10-21
2016-06-29

Copyright ©2024 才華齋 All Rights Reserved.