선 조치 후 분석

[ERROR] Java 오류 - Syntax error on token "class", @ expected 본문

ETC/Error

[ERROR] Java 오류 - Syntax error on token "class", @ expected

JB1104 2022. 2. 9. 23:24
728x90
반응형
SMALL

가끔씩 'Syntax error on token "class", @ expected ' 에러를 볼 수 있을 것이다.

 

이유는 간단하다. 클래스를 메서드처럼 사용하려고 했기 때문이다.  아래 코드를 보자.

public class StatufulServiceTest {
	@Test
	void statefulServiceSingleton() {
	}
	
	static class TestConfig() { // --> 클래스를 메서드처럼 사용!!! '()'을 생략 해야한다.
		
		public StatefulService statefulService() {
			return new StatefulService();
		}
	}
}

 

static class TestConfig()를 static class TestConfig변경하면 에러 해결이다.

public class StatufulServiceTest {
	@Test
	void statefulServiceSingleton() {
	}
	
	static class TestConfig {
		
		public StatefulService statefulService() {
			return new StatefulService();
		}
	}
		
}

 

728x90
반응형
LIST