由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - interesting
相关主题
请教一个简单的问题这段程序的输出是什么? 为什么
简单问题菜鸟问个简单的问题
初学者code请教 (大牛莫取笑)问一个java基础的初始化的问题,一直搞不明白 (转载)
help "java.lang.NoSuchMethodError"问个题
java reflecton question: how to represent a String[] class?问个autoboxing的问题
问个primitive type的问题java beginner question
折腾了一天,实在是绝望了,请教请教Re: 怎样不用main(String args[])输出"hello worl
一道java面试题 (转载)请帮忙看看这个编译错误
相关话题的讨论汇总
话题: class话题: string话题: public话题: static
进入Java版参与讨论
1 (共1页)
c*****t
发帖数: 1879
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
g*****g
发帖数: 34805
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)

s***e
发帖数: 122
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

s***e
发帖数: 122
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)

s******n
发帖数: 876
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)

c*****t
发帖数: 1879
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.

s***e
发帖数: 122
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

c*****t
发帖数: 1879
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.
s***e
发帖数: 122
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.

1 (共1页)
进入Java版参与讨论
相关主题
请帮忙看看这个编译错误java reflecton question: how to represent a String[] class?
请教大家:如何modify java code in order to compile问个primitive type的问题
weird class definition折腾了一天,实在是绝望了,请教请教
multiple classes in one file一道java面试题 (转载)
请教一个简单的问题这段程序的输出是什么? 为什么
简单问题菜鸟问个简单的问题
初学者code请教 (大牛莫取笑)问一个java基础的初始化的问题,一直搞不明白 (转载)
help "java.lang.NoSuchMethodError"问个题
相关话题的讨论汇总
话题: class话题: string话题: public话题: static