欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java finally return 类型 迷惑

程序员文章站 2022-06-05 23:28:05
...
package com.bobo;

public class Test {

/**
* QQ:15221860
* @param args
*/
public static void main(String[] args) {

System.out.println(getA());

System.out.println(getStudent().name);

}

static String getA() {

String a = "1";
try {
return a;
} catch (Exception e) {
a = "2";
return a;
} finally {
System.out.println("hi");
a = "3";
}

}

static Student getStudent() {

Student a = new Student();
a.name = "1";
try {
return a;
} catch (Exception e) {
a.name = "2";
return a;
} finally {
System.out.println("hi");
a.name = "3";

}

}

static class Student {
String name = "";

}

}
相关标签: finally return