You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Donny (JIRA)" <ji...@apache.org> on 2016/04/05 06:02:25 UTC
[jira] [Created] (GROOVY-7809) Create a map from an Object's
selected properties
Donny created GROOVY-7809:
-----------------------------
Summary: Create a map from an Object's selected properties
Key: GROOVY-7809
URL: https://issues.apache.org/jira/browse/GROOVY-7809
Project: Groovy
Issue Type: New Feature
Components: syntax
Reporter: Donny
Priority: Minor
It would be nice if Groovy allows developers to create a map from an Object's selected properties
Below are the example:
{code:title=Example|theme=FadeToGrey|linenumbers=true|language=groovy|firstline=0001|collapse=false}
class Hero {
String name
Integer strength
Integer constitution
String weakness
}
Hero hero = new Hero(name: "Robin", strength: 70, constitution: 80, weakness: "Beautiful Women")
def mapNoWeakness = hero.asMap(['name', 'strength', 'constitution'])
println mapNoWeakness // [name: 'Robin', strength: 70, constitution: 80]
def mapOnlyName = hero.asMap(['name'])
println mapOnlyName // [name: 'Robin']
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)