

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
@SafeVarargs annotation for private methods in Java 9?
The @SafeVarargs annotation was introduced in Java 7. This annotation applies to both final and static methods or constructors that take varargs parameters. This annotation used to make sure that a method does not perform unsafe operations on its varargs parameters. Since Java 9, @SafeVarargs annotation also applies to private instance methods.
Syntax
@SafeVarargs private void methodName(...) { // some statements }
Example
import java.util.ArrayList; import java.util.List; public class SafevarargsTest { @SafeVarargs // Apply @SafeVarargs to private methods private void display(List<String>... names) { for(List<String> name : names) { System.out.println(name); } } public static void main(String args[]) { SafevarargsTest test = new SafevarargsTest(); List<String> list = new ArrayList<String>(); list.add("TutorialsPoint"); list.add("Tutorix"); test.display(list); } }
Output
[TutorialsPoint, Tutorix]
- Related Questions & Answers
- Private Methods in Java 9 Interfaces
- Why @SafeVarargs is required in Java 9?
- What are the rules for private methods in an interface in Java 9?
- Can we use private methods in an interface in Java 9?
- Why do we need private methods in an interface in Java 9?
- What are the improvements for @Deprecated annotation in Java 9?
- What are the advantages of private methods in an interface in Java 9?
- Can we override private methods in Java
- Private and final methods in Java Programming
- Can I overload private methods in Java?
- Private Methods in C#
- Which factory methods have added for collections in Java 9?
- Which attributes have added to @Deprecated annotation in Java 9?
- What are the conditions for Collection factory methods in Java 9?
- Private and final methods in C#
Advertisements