How to create a custom EL function to invoke a static method?

First create a final class with a public static method which does exactly the job you want: package com.example; import java.util.Collection; public final class Functions { private Functions() { // Hide constructor. } public static boolean contains(Collection<Object> collection, Object item) { return collection.contains(item); } } Then define it as a facelet-taglib in /WEB-INF/functions.taglib.xml: <?xml version=”1.0″ … Read more

Meaning of @classmethod and @staticmethod for beginner? [duplicate]

Though classmethod and staticmethod are quite similar, there’s a slight difference in usage for both entities: classmethod must have a reference to a class object as the first parameter, whereas staticmethod can have no parameters at all. Example class Date(object): def __init__(self, day=0, month=0, year=0): self.day = day self.month = month self.year = year @classmethod … Read more

When to use static methods

One rule-of-thumb: ask yourself “Does it make sense to call this method, even if no object has been constructed yet?” If so, it should definitely be static. So in a class Car you might have a method: double convertMpgToKpl(double mpg) …which would be static, because one might want to know what 35mpg converts to, even … Read more

Static methods in Python?

Yep, using the staticmethod decorator class MyClass(object): @staticmethod def the_static_method(x): print(x) MyClass.the_static_method(2) # outputs 2 Note that some code might use the old method of defining a static method, using staticmethod as a function rather than a decorator. This should only be used if you have to support ancient versions of Python (2.2 and 2.3) … Read more