问题是我想要更改类中方法的字节代码。 假设我们有这个方法:
public class Test{
public Connection buildConnection(){
Connection connection = null;
if(connection==null){
connection = Mysql.getConnection();
}
if(connection==null){
throw new RunTimeException("Error");
}
return connection;
}
}
有没有办法在运行时模式下更改此代码以匹配以下内容:
public class Test{
public Connection buildConnection(){
Connection connection = null;
if(connection==null){
connection = Mysql.getConnection();
}else{
connection = Oracle.getConnection();
}
if(connection==null){
throw new RunTimeException("Error");
}
return connection;
}
}