简体   繁体   English

Eclipse Java 调试模式:如何获取实际类型的值?

[英]Eclipse Java debug mode: how to get actual type of value?

The variable view of Eclipse Java Debug mode allows to inspect the values of variables. Eclipse Java Debug 模式的变量视图允许检查变量的值。 If the type of a variable has several sub-types, how to find out the actual type of the value?如果一个变量的类型有多个子类型,如何找出值的实际类型?

Eclipse Standard/SDK Eclipse 标准/SDK

Version: Luna Service Release 1 (4.4.1) Build id: 20140925-1800版本:Luna Service Release 1 (4.4.1) 版本号:20140925-1800

Use expressions view.使用表达式视图。 If for example your variable name is x add x.getClass() to expressions view and see the type.例如,如果您的变量名称是xx.getClass()添加到表达式视图并查看类型。

use ctrl+shift+I for inspect expressions/variables in debug mode of eclipse在 Eclipse 的调试模式下使用ctrl+shift+I检查表达式/变量

let say i have below code假设我有以下代码

Example:例子:

List<String> strLst = commonService.getUserdetail();

and i want to know value of strLst than我想知道 strLst 的值比

select commonService.getUserdetail() and than press ctrl+shift+I it will give you value that comes from commonService.getUserdetail() method选择commonService.getUserdetail()然后按 ctrl+shift+I 它会给你来自commonService.getUserdetail()方法的值

go HERE to know more about debuging in eclipse这里了解更多关于在 Eclipse 中调试的信息

This should be easier with Eclipse 4.17 (2020-09 release) :使用Eclipse 4.17(2020-09 版本)应该会更容易:

Actual type in Variables view变量视图中的实际类型

The option Show Type Names in the Variables and Expressions views now displays the value's actual type instead of its declared type.变量和表达式视图中的Show Type Names选项现在显示值的实际类型而不是其声明的类型。
This simplifies debugging especially when variable details ( toString() ) is shown As the label for all variables .这简化了调试,尤其是当变量详细信息 ( toString() ) 显示为所有变量的标签时

To enable Show Type Names in the Variables view , column mode must be disabled ( View Menu > Layout > Show Columns ).要在变量视图中启用Show Type Names ,必须禁用列模式( View Menu > Layout > Show Columns )。

Example:例子:

 Object s = "some string"; Collection<?> c = Arrays.asList(s, 1); // breakpoint

https://www.eclipse.org/eclipse/news/4.17/images/variables-actual-type.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM