• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Lambda function

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have problem, I am trying to use lambda functions inside map to copy value of object from one to another object, I have expressions like

a.b.p1 =d.e.d1
or
a.x1 = d.e.d2;

and class like

class a
{
  int x1;
  class b
  {
     String p1;
     String p2
   }
}

class d
{
  class e
  {
     String d1;
     String d2;

   }
}

I need to copy as per expression
a.b.p1 =d.e.d1
or
a.x1 = d.e.d2;

copy d1 from object d.e to p1 of object a.b
and similarly
in second case
copy d2 from object d.e to object a.x1;

I was tryiing to create a map of expression vs functions
Map<String, FunctionalInterface>

but can I get  help from some expert developer, how this can be done?

Thank you for your help, Younis
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please use the code button, in which case the code will look like this:-

Younis ahmed wrote:. . . I am trying to use lambda functions inside map to copy value of object from one to another object, I have expressions like

a.b.p1 =d.e.d1
or
a.x1 = d.e.d2;
. . . .

Who gave you that code? Please always tell us where such code comes from. There is nothing good one can say about that code, neither in terms of style nor of design. Assuming those two classes are in the same package, they have access to each other's implementation details because their fields aren't private. Also, the use of inner classes makes that code difficult to execute. If you are still going to use inner classes, go through the Java™ Tutorials and see how to instantiate them. And I am not even starting about style things.
I can see all sorts of errors in the copying code “a.x1 = d.e.d2;”: you are confusing inner and outer classes, you are confusing static and instance fields, and you are confusing different types.
Why are you calling that a λ function? It doesn't look like a λ to me. What do you mean about being in a map?
reply
    Bookmark Topic Watch Topic
  • New Topic