参数转换如何在此程序中工作?

时间:2016-06-06 12:14:08

标签: java

我有两个示例程序来理解Java中的参数转换。

计划1:

locality <- c(
            "NEAR HAENA BEACH PARK, N 22 13 W 159 34 500 meters from coast",
            "NEAR HAENA BEACH PARK, N 22 13 45 W 159 34 23 500 meters from coast",
            "NEAR HAENA BEACH PARK, N 22 13 12.32 W 159 34  500.4 meters from coast",
            "NEAR HAENA BEACH PARK, E 22 13 S 159 34 500 meters from coast",
            "NEAR HAENA BEACH PARK, N 22 13' W 159 34' 500 meters from coast",
            "NEAR HAENA BEACH PARK, N 22 13' W 159 34' 500 km from coast"
            "NEAR HAENA BEACH PARK, N 22 13' W 159 34' 500 distance from coast"
            )


regex <- "[NSEW]\\b([0-9]*\\.?[0-9]+)?(\\$O)?(\\s)?[0-9]*\\.?[0-9]+(\\')?(\\$O)?\\s([0-9]*\\.?[0-9]+(\\')?)(?!\\sMI\\b|KM\\b|M\\b|MILES|KILOMETERS|METERS)"

> capture <- gregexpr(regex, locality[1], ignore.case = TRUE, perl = TRUE)
> regmatches(locality[1], capture)
[[1]]
[1] "N 22 13"  "W 159 34"

> 
> capture <- gregexpr(regex, locality[2], ignore.case = TRUE, perl = TRUE)
> regmatches(locality[2], capture)
[[1]]
[1] "N 22 13"  "W 159 34"

> 
> capture <- gregexpr(regex, locality[3], ignore.case = TRUE, perl = TRUE)
> regmatches(locality[3], capture)
[[1]]
[1] "N 22 13"  "W 159 34"

> 
> capture <- gregexpr(regex, locality[4], ignore.case = TRUE, perl = TRUE)
> regmatches(locality[4], capture)
[[1]]
[1] "E 22 13"  "S 159 34"

> 
> capture <- gregexpr(regex, locality[5], ignore.case = TRUE, perl = TRUE)
> regmatches(locality[5], capture)
[[1]]
[1] "N 22 13'"  "W 159 34'"

> 
> capture <- gregexpr(regex, locality[6], ignore.case = TRUE, perl = TRUE)
> regmatches(locality[6], capture)
[[1]]
[1] "N 22 13'"  "W 159 34'"

> 
> capture <- gregexpr(regex, locality[7], ignore.case = TRUE, perl = TRUE)
> regmatches(locality[7], capture)
[[1]]
[1] "N 22 13'"  "W 159 34'"

计划2:

public class TestRunner {

    public static void main(String[] args) {

        TestRunner r = new TestRunner();
        r.call(null);
     }

    void call(Object obj){
        System.out.println("I am from object");
    }
    void call(String obj){
        System.out.println("I am from string");
    }

 }

程序1打印“我来自字符串” 程序2给出了编译错误。

请解释我的工作原理。

0 个答案:

没有答案