
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
@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 Articles
- Private Methods in Java 9 Interfaces
- What are the rules for private methods in an interface in Java 9?
- Why @SafeVarargs is required 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 advantages of private methods in an interface in Java 9?
- What are the improvements for @Deprecated annotation in Java 9?
- Private and final methods in Java Programming
- Can I overload private methods in Java?
- Can we override private methods in Java\n
- 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