Add or modify keywords in java language

前端 未结 6 784
不知归路
不知归路 2020-12-16 02:47

I know my question does not seem valid, but it is genuine. When writing java I must use the word import so as to import classes from classpath. It is required t

6条回答
  •  别那么骄傲
    2020-12-16 03:20

    You can't really solve this to work generically; java strictly defines the keywords in its language specification and there is no mechanism in the java language to add keywords (e.g. macros).

    A partial solution would be to create a preprocessor that translates your new keywords into plain java. Needless to say that this is a pain to integrate into common tool chains and you won't get useful compiler error messages any more for constructs created by the preprocessor.

    One step further would be to write your own compiler; again this integrates poorly with existing toolchains. You still don't get proper support from your IDE.

    As fascinating as the idea is; the obstacles make it highly impractical for generic use.

    The situation is different in languages that come with a compile time macro language (most assembler langauges have this). C's define is another example. They still all have the problem that they are preprocessor based, so added constructs are more complicated (only basic syntax checking etc.)

提交回复
热议问题