英文:
Java - and is the code to examine the source code of custom user defined methods (see the code from within the program)
问题
寻找在Java程序中显示用户创建的自定义方法代码的方法。我想查看特定命名的自定义Java方法的代码。我不是在寻找查看Java内置的标准方法的方法。
在R中,轻松查看用户创建的函数的代码或查看许多内置函数的代码。只需输入函数名称,不要加尾括号。例如,从函数data.frame显示的代码部分如下所示。似乎在Java中应该有类似的功能。
data.frame
function (...,row.names = NULL,check.rows = FALSE,check.names = TRUE,
fix.empty.names = TRUE,stringsAsFactors = default.stringsAsFactors())
{
data.row.names <- if(check.rows && is.null(row.names))
function(current,new,i){
if(is.character(current))
new <- as.character(new)
if(is.character(new))
current <- as.character(current)
if(anyDuplicated(new))
return(current)
if(is.null(current))
return(new)
if(all(current == new)|| all(current == ""))
return(new)
stop(gettextf("在'数据框'参数的行名称不匹配,项目 %d",
i),domain = NA)
}
else function(current,new,i){
if(is.null(current)){
if(anyDuplicated(new)){
warning(gettextf("一些行名称重复:%s --> 行名称未使用",
paste(which(duplicated(new)),collapse = ",")),
domain = NA)
current
}
else new
}
else current
}
object <- as.list(substitute(list(...)))[-1L]
mirn <- missing(row.names)
mrn <- is.null(row.names)
x <- list(...)
n <- length(x)
if(n < 1L){
if(!mrn){
if(is.object(row.names)||!is.integer(row.names))
row.names <- as.character(row.names)
if(anyNA(row.names))
stop("行名称包含缺失值")
if(anyDuplicated(row.names))
stop(gettextf("重复的行名称:%s",paste(unique(row.names [duplicated(row.names)]),collapse = ",")),
domain = NA)
}
else row.names <- integer()
return(structure(list(),names = character(),row.names = row.names,
class = "data.frame"))
}
vnames <- names(x)
等等...................
英文:
Looking for the way to accomplish showing the code for custom methods created by the user within a java program. I want to view the code for specifically named custom java methods. I am not looking for the way to view the code for those standard methods built into java.
In R, it's easy to see the code for either the user created functions, or view the code for many of the built-in functions. Just enter the name of the function without trailing parenthesis. For example, a portion of the code that is displayed from the function data.frame is shown below. It seems reasonable there should be a similar feature in java.
data.frame
function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,
fix.empty.names = TRUE, stringsAsFactors = default.stringsAsFactors())
{
data.row.names <- if (check.rows && is.null(row.names))
function(current, new, i) {
if (is.character(current))
new <- as.character(new)
if (is.character(new))
current <- as.character(current)
if (anyDuplicated(new))
return(current)
if (is.null(current))
return(new)
if (all(current == new) || all(current == ""))
return(new)
stop(gettextf("mismatch of row names in arguments of 'data.frame', item %d",
i), domain = NA)
}
else function(current, new, i) {
if (is.null(current)) {
if (anyDuplicated(new)) {
warning(gettextf("some row.names duplicated: %s --> row.names NOT used",
paste(which(duplicated(new)), collapse = ",")),
domain = NA)
current
}
else new
}
else current
}
object <- as.list(substitute(list(...)))[-1L]
mirn <- missing(row.names)
mrn <- is.null(row.names)
x <- list(...)
n <- length(x)
if (n < 1L) {
if (!mrn) {
if (is.object(row.names) || !is.integer(row.names))
row.names <- as.character(row.names)
if (anyNA(row.names))
stop("row names contain missing values")
if (anyDuplicated(row.names))
stop(gettextf("duplicate row.names: %s", paste(unique(row.names[duplicated(row.names)]),
collapse = ", ")), domain = NA)
}
else row.names <- integer()
return(structure(list(), names = character(), row.names = row.names,
class = "data.frame"))
}
vnames <- names(x)
etc ...................
答案1
得分: 2
你也可以在Java中看到他人编写的函数,但你必须通过源代码来实现。如果你使用的是集成开发环境(IDE),你应该有一个“显示声明”功能。例如,在IntelliJ中,只需对着方法调用按下Ctrl键并点击鼠标左键,就能显示出执行的代码。
你在R或者例如Python中看到的这个特性更常见,因为它们是解释性语言。通过Java的REPL(交互式编程环境)——Jshell,你可以直接从REPL中查看Java文档,详见https://cr.openjdk.java.net/~rfield/tutorial/JShellTutorial.html#tab-completion----snippets。
英文:
You can see functions made by other in Java too, but you have to do it through the source code. If you have an IDE, you should have a "show declaration" features. For example, in IntelliJ, simply ctrl-leftclick on a method call will show you what code is executed.
The feature you see here in R or for example Python is more often seen in langage that can be interpreted. With Jshell, which is the REPL of Java, you can have glimpse of java doc from the REPL directly, see https://cr.openjdk.java.net/~rfield/tutorial/JShellTutorial.html#tab-completion----snippets
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论