开发者

In the Eclipse debugger, how can I view any primitive long value as a formatted date?

开发者 https://www.devze.com 2023-02-01 13:15 出处:网络
I\'m currently working on a Java application that frequently uses pr开发者_如何学编程imitive long values for timestamps. It would be great if I could see these in the Eclipse debugger as both a long v

I'm currently working on a Java application that frequently uses pr开发者_如何学编程imitive 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


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 a long 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 all long values because those generally aren't all timestamps.


You can write your own formatter to transform any value/object:

In the Eclipse debugger, how can I view any primitive long value as a formatted date?

with:

In the Eclipse debugger, how can I view any primitive long value as a formatted date?

into any presentation you want:

In the Eclipse debugger, how can I view any primitive long value as a formatted date?


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:

In the Eclipse debugger, how can I view any primitive long value as a formatted date?

So it will be valid for any variable/instances of that type.

0

精彩评论

暂无评论...
验证码 换一张
取 消