public void testMethod(){ Test1 t1 = new Test1(); t1.my(); } public static void main(String[] args) { Test t = new Test(); t.testMethod(); } class Test1{ public void my(){ String tag = this.getMyGrandpaStackTrace(); System.err.println(String.format("
如果另一个类中的那个方法是私有的话,就不能直接调用到,如果是其他类型的话看情况,如果是静态的(static)话,直接用类名可以调用到,如果是非静态的,就需要利用另一个类的实例(也就是用那个类生成的对象)来调用. 如 class A{public static void a(){}public void b(){} } public class B{public static void main(String[] args){A.a();//静态 new A().b();//非静态}}
@Transactional 内部调用例子 在 Spring 的 AOP 代理下,只有目标方法由外部调用,目标方法才由 Spring 生成的代理对象来管理,这会造成自调用问题.若同一类中的其他没有@Transactional 注解的方法内部调用有@Transactional 注解的方法,有@Transactional 注解的方法的事务被忽略,不会发生回滚 @Service public class A{ public void action(){ dosome(); } @Transaction
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; class test { { Console.WriteLine("1:__" + "Method调用成功!"); } { Console.WriteLine("2:__" + str); } { string classNam
带有静态方法的类通常(虽然不一定是这样)不打算被初始化. 可以用私有构造函数来限制非抽象类被初始化. 例如,java中的math类.它让构造函数标记为私有,所以你无法创建Math的实例.但Math类却不是静态类. 下面是math类: public final class Math { /** * Don't let anyone instantiate this class. */ private Math() {} public static final double E = 2.718281