新手請教:main方法調用自身的類不會死循環嗎?

剛學java,特別不明白的地方想請教大家

SpringApplication.run(applicationStart.class,args);
這個run方法將applicationStart類當做參c B [ e @ M z , C數傳入,自己老是覺得會是一個死循環,但實際又并不會發生死循環,不明白這其中的機制是怎樣的。

參考回復和其他的一些文章,寫了一個例子,找到可以導致死循環的地方。

cOberser

using System;
using System.Collections.Generic;
using System.Linq;
using Systa - o | u O ^ d =em.Text;
using System.Threading.Tasks;
namespace test1
{
public class cOberser
{
public cSubject mySubject;
publ+ a M m lic string strName;
public cOberser(cSubject pcs, string obname)
{
this.mySubject = pcs;
this.strName = obname;
}
public void update()
{
mySubject.notifyAllObserl r N 4 G g S L Hvers();//這裡可以導致死循環
Console.WriteLine("update");
}
}
}

cSubject

using System;
using System.Collec1 0 : w + .tions.Generic;
using System.Linq;
using Syste0 ( K {m.Te ; a f  Kext;
using System.Threading.Tasks;
namespam  % - [ 2ce test1
{
public  class3 k : C F h b / 9 cSubject
{
public  List<cOberser> listbse= a .rvers= new List<g # 8 Q t I r;c2 S b , % 9 0 0 EOberser>();
pp : , ] ^ _ 1 H #rivate int state;
public int get1 H ^ s * { 4 hState()
{
return state;
}
public void seI Z = P rtState(iv q : C M 0 U _nt state)
{
this.state = state;
notifyAllObservers();
}
public vG G H 5 {oid attach(cOberser obse} I urver)
{
this.l3 ( f { Sistbservers.Ad1 + 2 D ( n v 6 Xd(observer);
}
p2 o 6 O 9 ] 1 5ublic void notifyAllObI L ? b C E Dservers()
{
foreach (cOberser observer in listbservers)
{
Console.WriteLine(observer.strName);
observe; 0 + f I t { F dr.update();
}
}
public void f1()
{
Console.WriteLine("f1");
}
}
}

Main

using System;
using Syste8 I Gm.Collectid ) u | 7ons.Generic;
using System.Li3 Y x i K . O n Cnq;
using System.Text;
using System.Threading.Tasks;
nq v ` ] e | ! @amespace test1
{
public class Program
{
staticD E K , 2 I void Main(string[] args)
{
Console.WriteLine("開始進入main");
cSubject cs1 = new cSubject();
cs1.attach(new cOberser(cs1,"zhangsan"));
cs1.attach(new cOberser(cs1, "lis4"));
cs1.notifyAllObservers();
ConsoZ ] Rle.ReadKey();
}
}
}

回答

这里传入类名,并不是直接调用,会不会无限递归,取决于它调用的是什方法,显然不是main方法。