{"id":2409,"date":"2025-12-23T10:00:02","date_gmt":"2025-12-23T15:00:02","guid":{"rendered":"http:\/\/www.mymiller.name\/wordpress\/?p=2409"},"modified":"2025-12-23T10:00:02","modified_gmt":"2025-12-23T15:00:02","slug":"java-getter-setter-used-as-lamdas","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/lambda_stream\/java-getter-setter-used-as-lamdas\/","title":{"rendered":"Java getter\/setter used as Lamda&#8217;s"},"content":{"rendered":"\n<p>Once again I&#8217;m looking into ways to make coding so much easier.  I needed to be able to pass in a Class::get and a Class:set as a Lamda in order to be able to reuse code across types.  It&#8217;s a rather simple process. However I have not found it really documented elsewhere. Therefore I hope this article helps someone on this issue.<br\/><br\/>The getter is simple: Function&lt;? super T,? extends R> getter<br\/>Use this Functional Interface to be able to pass in your getter. Class::get\n<br\/>The setter is simple: BiConsumer&lt;T, R> setter<br\/>Use this Functional Interface to be able to pass in your setting. Class:set<br\/><br\/>Here is a simple Java Bean we will use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Person {\n\tprivate String name;\n\n\t\/**\n\t * @return the name\n\t *\/\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\t\/**\n\t * @param name the name to set\n\t *\/\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n}<\/code><\/pre>\n\n\n\n<p>Here is our Actor class that will operate on the Java Beam:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Actor {\n\tpublic &lt;T> void printField(T obj, Function&lt;? super T,? extends R> getter) {\n\t\tSystem.out.println(getter.apply(obj).toString());\n\t}\n\t\t\n\tpublic &lt;T,R> void setField(T obj, R value, BiConsumer&lt;T, R> setter) {\n\t\tsetter.accept(obj, value);\n\t}\n\t\t\n\tpublic static void main(String[] args) {\n\t\tPerson person = new Person();\n\t\tActor actor = new Actor();\n\t\t\t\n\t\tactor.setField(person, \"Bob\", Person::setName);\n\t\tactor.printField(person, Person::getName);\n\t}\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Once again I&#8217;m looking into ways to make coding so much easier. I needed to be able to pass in a Class::get and a Class:set as a Lamda in order to be able to reuse code across types. It&#8217;s a rather simple process. However I have not found it really documented elsewhere. Therefore I hope [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2412,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[456],"tags":[69],"series":[],"class_list":["post-2409","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lambda_stream","tag-java-2"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2018\/10\/coffee-cup-2317201_640.jpg?fit=640%2C426&ssl=1","jetpack-related-posts":[{"id":2866,"url":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/complex-queries-for-java-data\/","url_meta":{"origin":2409,"position":0},"title":"Complex Queries for Java data","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Recently a project I was working on called for a complex filter that was needed for selecting specific elements from a large data set. Looking at various methods of doing this, none provided a simple method to do so. First I wrote out my own Predicate<T> that was ugly with\u2026","rel":"","context":"In &quot;Java Extras&quot;","block_context":{"text":"Java Extras","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_extra\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2020\/10\/maze-2264_640.jpg?fit=640%2C256&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2020\/10\/maze-2264_640.jpg?fit=640%2C256&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2020\/10\/maze-2264_640.jpg?fit=640%2C256&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3614,"url":"https:\/\/www.mymiller.name\/wordpress\/java\/lombok-annotations-that-do-the-heavy-lifting\/","url_meta":{"origin":2409,"position":1},"title":"Lombok: Annotations That Do the Heavy Lifting","author":"Jeffery Miller","date":"December 23, 2025","format":false,"excerpt":"If you\u2019re a Java developer who\u2019s tired of writing repetitive boilerplate code, Lombok is your new best friend. This clever library uses annotations to automatically generate common code elements, making your classes cleaner, more concise, and less error-prone. Why Lombok? The Benefits Reduced Boilerplate: Lombok takes care of getters, setters,\u2026","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/04\/ai-generated-8314612_640.jpg?fit=640%2C480&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/04\/ai-generated-8314612_640.jpg?fit=640%2C480&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/04\/ai-generated-8314612_640.jpg?fit=640%2C480&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":1927,"url":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/reflection-made-easy\/","url_meta":{"origin":2409,"position":2},"title":"Reflection made Easy!","author":"Jeffery Miller","date":"November 24, 2025","format":false,"excerpt":"I have not done any work prior to using reflection in my Java projects. \u00a0A project I was working on I needed to be able to access the Getter\/Setter of an object. \u00a0I honestly never dreamed it was this easy. \u00a0Four simple methods that make it extremely easy to access\u2026","rel":"","context":"In &quot;Java Extras&quot;","block_context":{"text":"Java Extras","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_extra\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/monkey-3512996_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/monkey-3512996_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/monkey-3512996_640.jpg?fit=640%2C426&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":2787,"url":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/calutils\/","url_meta":{"origin":2409,"position":3},"title":"CalUtils","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Recently had a need to break things out over a given date range into month-long increments. I found a solution that did this, however, I was not happy with it using the old Calendar() API. I set about creating a new implementation for this based on LocalDate. View this gist\u2026","rel":"","context":"In &quot;Java Extras&quot;","block_context":{"text":"Java Extras","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_extra\/"},"img":{"alt_text":"calendar","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2020\/04\/january-2290045_640.jpg?fit=640%2C396&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2020\/04\/january-2290045_640.jpg?fit=640%2C396&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2020\/04\/january-2290045_640.jpg?fit=640%2C396&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":2473,"url":"https:\/\/www.mymiller.name\/wordpress\/pipelines\/java-pipelines\/","url_meta":{"origin":2409,"position":4},"title":"Java Pipelines","author":"Jeffery Miller","date":"December 23, 2025","format":false,"excerpt":"Java streams introduced a new way to program for developers. Have a dataset and build a stream to filter, it maps it, and then collect it in the new form. This gave developers a powerful tool to use in development and data processing. I can't even begin to say how\u2026","rel":"","context":"In &quot;Pipelines&quot;","block_context":{"text":"Pipelines","link":"https:\/\/www.mymiller.name\/wordpress\/category\/pipelines\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/03\/machine-495376_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/03\/machine-495376_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/03\/machine-495376_640.jpg?fit=640%2C426&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":2967,"url":"https:\/\/www.mymiller.name\/wordpress\/angular\/translations-in-a-angular-library\/","url_meta":{"origin":2409,"position":5},"title":"Translations in a Angular Library","author":"Jeffery Miller","date":"January 1, 2021","format":false,"excerpt":"Developing a UI library for Angular, I had strings that needed be hardcoded. The question became how do I deal with them. I did not want to embed in ngx-translate into the library. I wanted the user to have the ability to modify the strings as well. So I created\u2026","rel":"","context":"In &quot;Angular&quot;","block_context":{"text":"Angular","link":"https:\/\/www.mymiller.name\/wordpress\/category\/angular\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/01\/globe-110775_640.jpg?fit=640%2C341&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/01\/globe-110775_640.jpg?fit=640%2C341&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/01\/globe-110775_640.jpg?fit=640%2C341&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/2409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=2409"}],"version-history":[{"count":4,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/2409\/revisions"}],"predecessor-version":[{"id":2414,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/2409\/revisions\/2414"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/2412"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=2409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=2409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=2409"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=2409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}