interface Refer { String m(String s); } class StringOperation { String reverse(String s) { String res = ""; for(int i=s.length()-1; i>=0; i--) res += s.charAt(i); return res; } } public class ReferDemo { static String compute(Refer r, String s) { return r.m(s); } public static void main(String[] args) { String s = "sample string"; System.out.println(compute(new StringOperation()::reverse, s)); /* Refer ob = (str)->{ String res = ""; for(int i=s.length()-1; i>=0; i--) res += s.charAt(i); return res; }; System.out.println(compute(ob, s)); */ } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter