English 中文(简体)
我们如何改变原 Java阶级的来源?
原标题:How do we modify the source of original Java classes?
  • 时间:2012-01-12 06:06:13
  •  标签:
  • java

现在,我很想知道,我是否可以修改和重组 Java基阶级?

我愿增加现有班级的职能,并能够称职。

例如,我要在java.lang。

public char[] getInternalValue(){
      return value;
}

我很想知道我们如何这样做?

最佳回答

您指的是:“monkey TOP。 这种做法在 Java是可能的,但这是不可取的,结果可能令人感兴趣。 您可以下载“Sting”类的源头,将其带入“JAR”,并预先将boot子排入:

-Xbootclasspath/p:MonkeyPatchedString.jar

用你自己取代现役。

http://www.tedneward.com/files/Papers/BootClasspath/BootClasspath.pdf”rel=“nofollow”>here

问题回答

If you do it, you get incompatible with the java.lang.String class, and with all classes, relying on java.lang.String, which is very, very rarely a good idea.

第二个问题是许可。 自我分析完全是罚款的,但如果你公布你的法典(有缺陷或来源),你应仔细阅读许可证条款。

由于Sting阶级被宣布为最终产物,你甚至可以继承Sting,执行你看来在初见时有用的PierierString。 但是,有这么多的人本来会执行很少的帮助者,我们会从各地获得很多特殊课程。

共同做法是人,撰写“Foo”类,增加一种方法

 public Foo toFoo () {
     // some conversion for String representation of Foo
 }

页: 1

但是,你可以写上一部装饰物的Wrapper。 你们也许不会把你的“快乐”带给一种方法,而如果这样做会成为这一目的的良好候选人,那么你将需要把它称作“稳定”方法。

   Foo foo = new Foo ("foobar", 42);
   foo.setMagic (foo.toString ().length); 

不要这样做。

如果你想要成为邪恶的话,你就能够利用反思来获得一系列str。 但是,当然没有保证今后会存在这一领域,正如......,它很可能是强制性的。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签