我目前正在开发一个经常使用原始长值作为时间戳的 Java 应用程序。如果我能在 Eclipse 调试器中将它们视为长值和格式化时间戳,那就太好了。也许如果该数字超出任何合理时间戳的范围,则它只会显示为数字。 Eclipse Preferences 的“Detail Formatters”部分没有为基元提供任何内容,至少我找不到。监视表达式不太好,因为它需要为每个具有原始长时间戳的类创建一个新的监视表达式 - 不值得花费精力。有谁知道另一种方法来一般将任何长值视为格式化时间戳?感谢您的帮助。
拜伦
I'm currently working on a Java application that frequently uses primitive long values for timestamps. It would be great if I could see these in the Eclipse debugger as both a long value and a formatted timestamp. Perhaps if the number is out of range for any reasonable timestamp, it would only appear as a number. The "Detail Formatters" section of Eclipse Preferences offers nothing for primitives, at least not that I can find. Watch expressions are not much good, because it requires making a new watch expression for each and every class having a primitive long timestamp--not worth the labor. Does anyone know of another way to generically view any long value as a formatted timestamp? Thanks for your help.
Byron
发布评论
评论(2)
最好的解决方案可能是更改应用程序,使其使用
Date
对象。这些基本上只是一个围绕long
的事物包装器,赋予它时间戳的语义。您遇到的问题是没有此类语义的直接结果,并且没有人尝试实现将它们添加到所有long
值中的方法,因为这些值通常不是所有时间戳。The best solution may be to change the application so that it uses
Date
objects instead. Those are basically nothing but a thing wrapper around along
that gives it the semantics of a timestamp. The problems you're having are the direct result of not having such semantics, and nobody though of implementing a way to add them to alllong
values because those generally aren't all timestamps.您可以编写自己的格式化程序来转换任何值/对象:
与:
到您想要的任何演示文稿中:
作为 OP Byron Hawkins 评论,这是一项努力,但可以与类关联(而不是像监视表达式那样在调试期间与变量关联),如 此处说明:
因此它将对该类型的任何变量/实例有效。
You can write your own formatter to transform any value/object:
with:
into any presentation you want:
As the OP Byron Hawkins comments, it is an effort, but which can be associated to a class (and not a variable during debug like a watch expression), as illustrated here:
So it will be valid for any variable/instances of that type.