当前位置: 首页>>代码示例>>Java>>正文


Java Field.set方法代码示例

本文整理汇总了Java中java.lang.reflect.Field.set方法的典型用法代码示例。如果您正苦于以下问题:Java Field.set方法的具体用法?Java Field.set怎么用?Java Field.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Field的用法示例。


在下文中一共展示了Field.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: CustomZombie

import java.lang.reflect.Field; //导入方法依赖的package包/类
public CustomZombie(Player player, PetBlock petBlock) {
    super(((CraftWorld) player.getWorld()).getHandle());
    this.b(true);
    try {
        final Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
        bField.setAccessible(true);
        final Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
        cField.setAccessible(true);
        bField.set(this.goalSelector, new UnsafeList<PathfinderGoalSelector>());
        bField.set(this.targetSelector, new UnsafeList<PathfinderGoalSelector>());
        cField.set(this.goalSelector, new UnsafeList<PathfinderGoalSelector>());
        cField.set(this.targetSelector, new UnsafeList<PathfinderGoalSelector>());
        this.getAttributeInstance(GenericAttributes.d).setValue(0.30000001192092896D * ConfigPet.getInstance().getModifier_petwalking());
        this.goalSelector.a(0, new PathfinderGoalFloat(this));
        this.goalSelector.a(1, new OwnerPathfinder(this,petBlock));
    } catch (final Exception exc) {
        PetBlocksPlugin.logger().log(Level.WARNING, "EntityNMS exception.", exc);
    }
    this.petBlock = petBlock;
    this.S = (float) ConfigPet.getInstance().getModifier_petclimbing();
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:22,代码来源:CustomZombie.java

示例2: hackNatives

import java.lang.reflect.Field; //导入方法依赖的package包/类
private static void hackNatives()
{
    String paths = System.getProperty("java.library.path");
    String nativesDir = "F:/GradleStore/caches/minecraft/net/minecraft/natives/1.10.2";
    
    if (Strings.isNullOrEmpty(paths))
        paths = nativesDir;
    else
        paths += File.pathSeparator + nativesDir;
    
    System.setProperty("java.library.path", paths);
    
    // hack the classloader now.
    try
    {
        final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
        sysPathsField.setAccessible(true);
        sysPathsField.set(null, null);
    }
    catch(Throwable t) {};
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:22,代码来源:GradleStart.java

示例3: addLibraryDir

import java.lang.reflect.Field; //导入方法依赖的package包/类
private static void addLibraryDir(String libraryPath) throws Exception {  
    Field userPathsField = ClassLoader.class.getDeclaredField("usr_paths");  
    userPathsField.setAccessible(true);  
    String[] paths = (String[]) userPathsField.get(null);  
    StringBuilder sb = new StringBuilder();  
    for (int i = 0; i < paths.length; i++) {  
        if (libraryPath.equals(paths[i])) {  
            continue;  
        }  
        sb.append(paths[i]).append(';');  
    }  
    sb.append(libraryPath);  
    System.setProperty("java.library.path", sb.toString());  
    final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");  
    sysPathsField.setAccessible(true);  
    sysPathsField.set(null, null);  
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:18,代码来源:OpenCV.java

示例4: setField

import java.lang.reflect.Field; //导入方法依赖的package包/类
/**
 * 设置给定的对象中给定名称的字段的值
 *
 * @param object              给定的对象
 * @param fieldName           要设置的字段的名称
 * @param newValue            要设置的字段的值
 * @param isFindDeclaredField 是否查找Declared字段
 * @param isUpwardFind        如果在当前类中找不到的话,是否取其父类中查找
 * @return 设置是否成功。false:字段不存在或新的值与字段的类型不一样,导致转型失败
 */
public static boolean setField(Object object, String fieldName, Object newValue, boolean isFindDeclaredField, boolean isUpwardFind) {
    boolean result = false;
    Field field = getField(object.getClass(), fieldName, isFindDeclaredField, isUpwardFind);
    if (field != null) {
        try {
            field.setAccessible(true);
            field.set(object, newValue);
            result = true;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            result = false;
        }
    }
    return result;
}
 
开发者ID:lfkdsk,项目名称:Just-Evaluator,代码行数:26,代码来源:ReflectUtils.java

示例5: clearPreloadTypedArrayIssue

import java.lang.reflect.Field; //导入方法依赖的package包/类
/**
     * Why must I do these?
     * Resource has mTypedArrayPool field, which just like Message Poll to reduce gc
     * MiuiResource change TypedArray to MiuiTypedArray, but it get string block from offset instead of assetManager
     */
    private static void clearPreloadTypedArrayIssue(Resources resources) {
        // Perform this trick not only in Miui system since we can't predict if any other
        // manufacturer would do the same modification to Android.
//        if (!isMiuiSystem) {
//            return;
//        }
        Log.w(TAG, "try to clear typedArray cache!");
        // Clear typedArray cache.
        try {
            Field typedArrayPoolField = ShareReflectUtil.findField(Resources.class, "mTypedArrayPool");

            final Object origTypedArrayPool = typedArrayPoolField.get(resources);

            Field poolField = ShareReflectUtil.findField(origTypedArrayPool, "mPool");

            final Constructor<?> typedArrayConstructor = origTypedArrayPool.getClass().getConstructor(int.class);
            typedArrayConstructor.setAccessible(true);
            final int poolSize = ((Object[]) poolField.get(origTypedArrayPool)).length;
            final Object newTypedArrayPool = typedArrayConstructor.newInstance(poolSize);
            typedArrayPoolField.set(resources, newTypedArrayPool);
        } catch (Throwable ignored) {
            Log.e(TAG, "clearPreloadTypedArrayIssue failed, ignore error: " + ignored);
        }
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:TinkerResourcePatcher.java

示例6: setup

import java.lang.reflect.Field; //导入方法依赖的package包/类
@Before
public void setup() throws IllegalAccessException, NoSuchFieldException {

	Assume.assumeTrue(System.getProperty("skip.long") == null);
	TestUtils.disableSslCertChecking();

	amazonS3Client = AmazonS3ClientBuilder.standard()
			.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
					LocalstackTestRunner.getEndpointS3(),
					LocalstackTestRunner.getDefaultRegion()))
			.withChunkedEncodingDisabled(true)
			.withPathStyleAccessEnabled(true).build();
	amazonS3Client.createBucket(bucketName);

	S3Config config = new S3Config();

	Field field = StorageServiceImpl.class.getDeclaredField("s3TransferManager");
	field.setAccessible(true);
	field.set(underTest, config.s3TransferManager(amazonS3Client));

	field = StorageServiceImpl.class.getDeclaredField("environment");
	field.setAccessible(true);
	field.set(underTest, environment);
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:25,代码来源:StorageServiceImplIntegration.java

示例7: scanIdAnnotations

import java.lang.reflect.Field; //导入方法依赖的package包/类
private static void scanIdAnnotations(Object target,  Field f, View view) {
    ViewId viewIds = f.getAnnotation(ViewId.class);
    if (viewIds != null) {
        View targetView = findViewByIds(view, viewIds.value());
        
        if (targetView == null && viewIds.optional()) {
            return;
        }
        else if (!viewIds.optional() && targetView == null) {
            throw new RuntimeException("Mandatory view id not found");
        }
        
        if (!f.isAccessible()) {
            f.setAccessible(true);
        }
        
        try {
            f.set(target, targetView);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-android,代码行数:25,代码来源:ViewAnnotations.java

示例8: fixInputMethodManagerLeak

import java.lang.reflect.Field; //导入方法依赖的package包/类
/**
 * 解决InputMethodManager内存泄露现象
 */
private static void fixInputMethodManagerLeak(Context destContext) {
    if (destContext == null) {
        return;
    }

    InputMethodManager imm = (InputMethodManager) destContext
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) {
        return;
    }

    String[] arr = new String[]{"mCurRootView", "mServedView", "mNextServedView"};
    Field f;
    Object obj_get;
    for (String param : arr) {
        try {
            f = imm.getClass().getDeclaredField(param);
            if (!f.isAccessible()) {
                f.setAccessible(true);
            } // author: sodino mail:[email protected]
            obj_get = f.get(imm);
            if (obj_get != null && obj_get instanceof View) {
                View v_get = (View) obj_get;
                if (v_get
                        .getContext() == destContext) { // 被InputMethodManager持有引用的context是想要目标销毁的
                    f.set(imm, null); // 置空,破坏掉path to gc节点
                } else {
                    // 不是想要目标销毁的,即为又进了另一层界面了,不要处理,避免影响原逻辑,也就不用继续for循环了
                    /*if (QLog.isColorLevel()) {
                        QLog.d(ReflecterHelper.class.getSimpleName(), QLog.CLR, "fixInputMethodManagerLeak break, context is not suitable, get_context=" + v_get.getContext()+" dest_context=" + destContext);
                    }*/
                    break;
                }
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
 
开发者ID:guzhigang001,项目名称:Bailan,代码行数:43,代码来源:BaseActivity.java

示例9: getUrl_should_return_Url_of_Type_String_StockFileLicenseProp

import java.lang.reflect.Field; //导入方法依赖的package包/类
@Test(groups = { "Getters" })
void getUrl_should_return_Url_of_Type_String_StockFileLicenseProp()
        throws NoSuchFieldException, IllegalAccessException {
    Field f = prop.getClass().getDeclaredField("mUrl");
    f.setAccessible(true);
    f.set(prop, "www.example.com");
    Assert.assertTrue(prop.getUrl().equals("www.example.com"));
}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:9,代码来源:StockFileLicensePropTest.java

示例10: setPrivateField

import java.lang.reflect.Field; //导入方法依赖的package包/类
public final static void setPrivateField(final Object obj, final String field_name, final Object value) {
	Field field = getFieldIncludingSuper(obj.getClass(), field_name);
	if (field != null) {
		field.setAccessible(true);
		try {
			field.set(obj, value);
		} catch (IllegalArgumentException | IllegalAccessException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:zc8424,项目名称:QuantTester,代码行数:12,代码来源:ReflectHelper.java

示例11: getFilterEditorial_should_return_media_Filter_Editorial_of_Type_Boolean

import java.lang.reflect.Field; //导入方法依赖的package包/类
@Test(groups = { "Getters" })
void getFilterEditorial_should_return_media_Filter_Editorial_of_Type_Boolean()
        throws NoSuchFieldException,
        IllegalAccessException {
    Assert.assertTrue(param.getFilterEditorial() == null);
    Field f = param.getClass().getDeclaredField("mFilterEditorial");
    f.setAccessible(true);
    f.set(param, true);
    Assert.assertEquals(true, param.getFilterEditorial().booleanValue());
}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:11,代码来源:SearchParametersTest.java

示例12: getCreatorName_should_return_media_CreatorName_ofType_String_StockLicenseHistoryFile

import java.lang.reflect.Field; //导入方法依赖的package包/类
@Test(groups = { "Getters" })
void getCreatorName_should_return_media_CreatorName_ofType_String_StockLicenseHistoryFile()
        throws NoSuchFieldException, IllegalAccessException {
    Field f = stocklicensehistoryfile.getClass().getDeclaredField("mCreatorName");
    f.setAccessible(true);
    f.set(stocklicensehistoryfile, "SomeText");
    Assert.assertTrue(stocklicensehistoryfile.getCreatorName().equals("SomeText"));
}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:9,代码来源:StockLicenseHistoryFileTest.java

示例13: setColor

import java.lang.reflect.Field; //导入方法依赖的package包/类
private void setColor(int color) {
    Field textColorField;
    try {
        textColorField = TextView.class.getDeclaredField("mCurTextColor");
        textColorField.setAccessible(true);
        textColorField.set(this, color);
        textColorField.setAccessible(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    mPaint.setColor(color);
}
 
开发者ID:star3136,项目名称:StrokeTextView,代码行数:13,代码来源:StrokeTextView.java

示例14: setValue

import java.lang.reflect.Field; //导入方法依赖的package包/类
/**
 * Update {@link #opcode} value.
 *
 * @param value
 */
private void setValue(int value) {
	try {
		Field op = AbstractInsnNode.class.getDeclaredField("opcode");
		op.setAccessible(true);
		op.set(opcode, value);
		list.repaint();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:Col-E,项目名称:Recaf,代码行数:16,代码来源:OpcodeTypeSwitchPanel.java

示例15: getCategoryId_should_return_IntegerValue_of_Field_CategoryId

import java.lang.reflect.Field; //导入方法依赖的package包/类
@Test(groups = { "Getters" })
void getCategoryId_should_return_IntegerValue_of_Field_CategoryId()
        throws NoSuchFieldException, IllegalAccessException {
    Field f = request.getClass().getDeclaredField("mCategoryId");
    f.setAccessible(true);
    f.set(request, 1231);
    Assert.assertEquals(1231, request.getCategoryId().intValue());
}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:9,代码来源:SearchCategoryRequestTest.java


注:本文中的java.lang.reflect.Field.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。