avatar
c*t
1
It is interesting that Java allows $ in the class name and thus you
can do the following:
In T.java
public class T
{
static class O
{
public static void run (String msg) { }
}
public static void main (String[] args)
{
T.O.run ("over");
}
}
Then in T$O.java
class T$O
{
public static void run (String msg) { System.out.println (msg); }
}
Compile T.java first, then T$O.java.
They probably allowed it so that some
avatar
g*g
2
I think it's allowed to have non-public class.
e.g.
In T.java
You have
public class T{}
class P{}
P will be compiled to be like T$P.class

【在 c*****t 的大作中提到】
: It is interesting that Java allows $ in the class name and thus you
: can do the following:
: In T.java
: public class T
: {
: static class O
: {
: public static void run (String msg) { }
: }
: public static void main (String[] args)

avatar
s*e
3
it's actually for nested class. in your case, it would still be P.class.

【在 g*****g 的大作中提到】
: I think it's allowed to have non-public class.
: e.g.
: In T.java
: You have
: public class T{}
: class P{}
: P will be compiled to be like T$P.class

avatar
s*e
4
it's a trick, and i believe it's better to not allow $ in class name in the
source code.

【在 c*****t 的大作中提到】
: It is interesting that Java allows $ in the class name and thus you
: can do the following:
: In T.java
: public class T
: {
: static class O
: {
: public static void run (String msg) { }
: }
: public static void main (String[] args)

avatar
s*n
5
it's not encouraged to have $ in identifiers in source code.
machine generated source codes don't need $ either; in your
example, simply nest O within T's source file.
byte codes on the other hand much use $ in proper places
according to the spec.

【在 c*****t 的大作中提到】
: It is interesting that Java allows $ in the class name and thus you
: can do the following:
: In T.java
: public class T
: {
: static class O
: {
: public static void run (String msg) { }
: }
: public static void main (String[] args)

avatar
c*t
6
I actually needed this trick for the following task:
User define and compile a class T (along with nested classes). Then
my code scans T's nested classes (or trying to do so). Then replace
the nested classes with additional functionalities.
Sort of like AspectJ. Doing post-compile modification, except I am
generating Java code rather than binary class directly.

the

【在 s***e 的大作中提到】
: it's a trick, and i believe it's better to not allow $ in class name in the
: source code.

avatar
s*e
7
i am curious why you would need to do so. it seems to me hacking.

【在 c*****t 的大作中提到】
: I actually needed this trick for the following task:
: User define and compile a class T (along with nested classes). Then
: my code scans T's nested classes (or trying to do so). Then replace
: the nested classes with additional functionalities.
: Sort of like AspectJ. Doing post-compile modification, except I am
: generating Java code rather than binary class directly.
:
: the

avatar
c*t
8
See this example:
http://code.google.com/p/cookcc/source/browse/#svn/trunk/tests/javaap/nestedclass
And look at WC1.java and WC1$Lexer.java.orig (added .orig for backup
purpose). This WC1$Lexer.java would be replaced by code generated
from a compiler-compiler.
It is not a good approach in general I agree, but I do see that it
makes it possible to organize files.

【在 s***e 的大作中提到】
: i am curious why you would need to do so. it seems to me hacking.
avatar
s*e
9
interesting. i have to admit that i don't have a whole picture of your code.
but it seems that you don't have to make Lex1 or Nested nested class. code
generation is necessary sometimes, but ways other than overwriting nested
class might be easier. btw: the project itself looks really good.

【在 c*****t 的大作中提到】
: See this example:
: http://code.google.com/p/cookcc/source/browse/#svn/trunk/tests/javaap/nestedclass
: And look at WC1.java and WC1$Lexer.java.orig (added .orig for backup
: purpose). This WC1$Lexer.java would be replaced by code generated
: from a compiler-compiler.
: It is not a good approach in general I agree, but I do see that it
: makes it possible to organize files.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。