Java

[Java-source quality] Redundant Modifier

byeongoo 2020. 5. 29. 19:09

다음과 같은 인터페이스를 작성하고 commit을 하자 코드 퀄리티 툴에서 경고 메시지를 주었습니다.

import org.springframework.web.multipart.MultipartFile;

public interface IFileService {

    public String deleteFile(String filePath) throws RuntimeException;

    public String restore(MultipartFile multipartFile)  throws RuntimeException;

}
Warning:(9, 5) Modifier 'public' is redundant for interface methods

redundant는 불필요한의 뜻으로 인터페이스의 메소드를 위한 public 접근자는 불필요하다는 것 입니다. 그 이유는 인터페이스에서 사용하는 메소드는 기본적으로 인터페이스내에 존재하는 메소드는 임의적으로 'public abstract' or 'public'으로 선언 되어지 때문입니다. 따라서 protected, private에만 접근자를 설정합니다.

 

수정한 코드는 아래와 같습니다.

import org.springframework.web.multipart.MultipartFile;

public interface IFileService {

    String deleteFile(String filePath) throws RuntimeException;

    String restore(MultipartFile multipartFile)  throws RuntimeException;

}