java中的替换宏 [英] substitution macro in java

查看:36
本文介绍了java中的替换宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有类似于c的java中可用的替换宏(如#define)?

是否存在java中的预编译?

bcz我有写作的家庭作业java程序,我必须使用System.out.println()函数近1000次。如果有任何替换宏我可以替换System.out.println

为sop。

is there any substitution macro (like #define) available in java similar to c?
is precompilation exist in java?
bcz i have home work of writing the java programs where i have to use System.out.println() function nearly 1000 times.if there exist any substitution macro i can replace System.out.println
as sop.

推荐答案

Java 没有预处理。但是,这并不妨碍您使用另一个(例如 C )编程语言的预处理器。
Java has no pre-processing. However, that does not prevent you using a pre-processor of another (for instance C) programming language.






您可以使用静态方法来实现宏行为。

Hi,

You can use, to achieve the macro behavior, a static method.
public class Utils {
   public static void print(String text) {
      // Stuff...
      System.out.println(text);
      // More stuff...
   }
}



然后,只需要调用它:


And then, is just call it:

Utils.print("OK!");



我希望这对你有所帮助


最好的问候:

Filipe Marques


I hope this has helped you

Best regards:
Filipe Marques


这篇关于java中的替换宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆