如何故意导致自定义java编译器警告消息? [英] How to intentionally cause a custom java compiler warning message?

查看:526
本文介绍了如何故意导致自定义java编译器警告消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正要提交一个丑陋的临时黑客,以便在我们等待修复外部资源时解决阻塞问题。除了用一个可怕的评论和一堆FIXME来标记它之外,我很乐意让编译器发出明显的警告信息作为提醒,所以我们不要忘记把它拿出来。例如,类似于:

I'm about to commit an ugly temporary hack in order to work around a blocking issue while we wait for an external resource to be fixed. Aside from marking it with a big scary comment and a bunch of FIXMEs, I'd love to have the compiler throw an obvious warning message as a reminder so we don't forget to take this out. For example, something like:

[javac] com.foo.Hacky.java:192: warning: FIXME temporary hack to work around library bug, remove me when library is fixed!

有没有办法可以通过我选择的消息引起故意编译警告?如果不这样做,最简单的事情是添加到代码中以抛出现有警告,可能是在违规行上的字符串中有一条消息,以便在警告消息中打印出来?

Is there a way I can cause an intentional compiler warning with a message of my choosing? Failing that, what's the easiest thing to add to the code to throw an existing warning, with perhaps a message in a string on the offending line so it gets printed in the warning message?

编辑:
不推荐使用的代码似乎没有为我做任何事情:

Deprecated tags don't seem to be doing anything for me:

/**
 * @deprecated "Temporary hack to work around remote server quirks"
 */
@Deprecated
private void doSomeHackyStuff() { ... }

在eclipse或sun javac 1.6(从ant脚本运行)中没有编译器或运行时错误,它肯定正在执行该函数。

No compiler or runtime errors in eclipse or from sun javac 1.6 (running from ant script), and it's definitely executing the function.

推荐答案

我见过的一种技术是将其与单元测试联系起来(你单元测试,对?)。基本上,一旦实现外部资源修复,您就会创建失败的单元测试。然后你评论单元测试,告诉别人如何在问题解决后撤消你的粗糙黑客。

One technique that I've seen used is to tie this into unit testing (you do unit test, right?). Basically you create a unit test that fails once the external resource fix is achieved. Then you comment that unit test to tell others how to undo your gnarly hack once the issue is resolved.

这种方法的真正优点是撤消黑客攻击的触发器是核心问题本身的解决方案。

What's really slick about this approach is that the trigger for undoing your hack is a fix of the core issue itself.

这篇关于如何故意导致自定义java编译器警告消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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