Which methods are with biggest number of arguments in the Java standard library?
Note: variable Arguments (Varargs) should be counted as 1 argument of type array instead of infinite number of arguments.
Reason: I'm trying to design better Libraries and I'm thinking of banning methods with more than 4 arguments maybe ... So I'm trying to find methods in the standard library that have a large number of arguments and study the method and think of if it was needed to be defined like that and if there is a valid case to have more than 4 arguments.
The goal of limiting the number of parameters in own, public APIs is certainly a good one, but one should not blindly obey arbitrary rules and then apply quirky workarounds to follow them. Also, other people's code should sometimes only be an inspiration of how to not solve something...
That said, answering the actual question is a bit difficult. Do you want to...
publicorprotectedmethods?publicclasses?public, but proprietary API?However, I was curious. Using a class to scan for all visible classes (+1 there!), loading them (and blatantly ignoring errors), obtaining all methods from the valid classes and having a look at their parameter count, I could find some results:
The overall winner seems to be from a class from the JavaFX runtime, called
com.sun.scenario.effect.impl.sw.sse.SSEPhongLighting_SPOTPeer. The method is anativemethod that is simply calledfilter, and receives a whopping 37 parameters:private static native void com.sun.scenario.effect.impl.sw.sse.SSEPhongLighting_SPOTPeer.filter(int[],int,int,int,int,int,int[],float,float,float,float,int,int,int,float,float[],float,float,float,float,float,float,float,float,float,float,int[],float,float,float,float,int,int,int,float,float,float).However, the method is
privateandnative, and the class cannot even be found in the OpenJDK JavaFX runtime repo, so I assume that it is auto-generated somehow.Limiting the whole search to
publicclasses and methods that are alsopublicorprotected(and notnative) still leads to one of the JavaFX classes. This time, it's in thecom.sun.prism.impl.VertexBufferclass, which has a method calledaddMappedPgram, with 24 parameters:public final void com.sun.prism.impl.VertexBuffer.addMappedPgram(float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float), and the repo also contains the source code of this method.This is an example of a method where most coding guidelines would say that the number of parameters is far too high. But the parameters are so "regular" (following a naming pattern, probably related to 4 corners of a quad) that I think that something like this can still be reasonable. But the class is still not supposed to be used by clients, and has to be considered as "proprietary API".
Omitting classes in packages that start with
"sun."or"com.sun."brings us to what probably can be considered "the correct answer" to the question: The classorg.w3c.dom.events.MouseEventcontains a method calledinitMouseEvent, which still receives 15 parameters:public abstract void org.w3c.dom.events.MouseEvent.initMouseEvent(java.lang.String,boolean,boolean,org.w3c.dom.views.AbstractView,int,int,int,int,int,boolean,boolean,boolean,boolean,short,org.w3c.dom.events.EventTarget). And here is the JavaDoc API documentation of that method.(A related side note: The function with the largest number of parameters that was supposed to be used by clients that I have encountered so far is a function from cuDNN with 31 parameters...)
Update
In response to the comments, I now also covered constructors.
The class
javafx.scene.input.ScrollEventhas two constructors with 23 parameters, namelypublic javafx.scene.input.ScrollEvent(javafx.event.EventType,double,double,double,double,boolean,boolean,boolean,boolean,boolean,boolean,double,double,double,double,double,double,javafx.scene.input.ScrollEvent$HorizontalTextScrollUnits,double,javafx.scene.input.ScrollEvent$VerticalTextScrollUnits,double,int,javafx.scene.input.PickResult)andpublic javafx.scene.input.ScrollEvent(java.lang.Object,javafx.event.EventTarget,javafx.event.EventType,double,double,double,double,boolean,boolean,boolean,boolean,boolean,boolean,double,double,double,double,javafx.scene.input.ScrollEvent$HorizontalTextScrollUnits,double,javafx.scene.input.ScrollEvent$VerticalTextScrollUnits,double,int,javafx.scene.input.PickResult). Here is the link to the API documentation for the latter.The code that I used for my tests - this is ugly and hacky, but I think it should be added here:
(Edited to also cover constructors, in response to the comment:)
(Note: The
ClassFinderis from https://stackoverflow.com/a/19554704/3182664 !)