Java
public class Sample {
public static void func(Action<String> a) {
a.apply('Hello');
}
public static void main(String[] args) {
Sample.func(s -> System.out.println(s));
//For multiple lines
Sample.func(s -> {
System.out.println(s)
System.out.println(s)
});
}
}
JavaScript
const func = (callback) => {
callback('Hello');
};
func((s) => console.log(s));
//For multiple lines
func((s) => {
console.log(s)
console.log(s)
});
Ruby
def func
yield 'Hello'
end
func { |s| p s }
#In the case of multiple business lines
func do |s|
console.log(s)
console.log(s)
end
# {}But it works but do~end is better
Recommended Posts