我是靠谱客的博主 可靠大叔,这篇文章主要介绍java两个类的对象直接复制,将Java对象/类从一个类装入器复制到另一个类装入器...,现在分享给大家,希望可以做个参考。

Hi is there a way to copy one class loaded context (atrributes etc) from one classloader (for instance a 'made' class Point) to another classloader?

Making clear,

Example:

I have an object Point on CL 1.

Now running on another CL2, I want to creat this object in CL 3.

Some obj:

class Point {

int x;

int y;

public Point() {}

//getters and setters

Scenery:

...

class CL2 {

// Running on CL 2

...

// Point obj from CL 1

Object point = gotFromCL1();

// Want to create the object on Cl2

Object pointCL2 = point.conversion();

But I can't use sun.reflection (not available) and serialization doesn't work since CL2 automatically "reconstruct" the object with CL 1.

One solution that I tought was do an "100%" java reflection rconstruct, basically getting the fields of object from CL2 and setting up on the new obj.

PS: It needs to run on Java 1.4.2 :'(

解决方案

See Transloader on how to copy classes between ClassLoaders if you need to do one of the following:

Clone almost any object graph from one ClassLoader to another

Take any object from a foreign ClassLoader and invoke any method on it without cloning it

最后

以上就是可靠大叔最近收集整理的关于java两个类的对象直接复制,将Java对象/类从一个类装入器复制到另一个类装入器...的全部内容,更多相关java两个类内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(159)

评论列表共有 0 条评论

立即
投稿
返回
顶部