Swapna latha

Ranch Hand
+ Follow
since Dec 18, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Swapna latha

Thank you so much for posting the stackoverflow link. I understood now.

Mikalai Zaikin wrote:Your code is not a lambda expression but rather a method reference. And they have indeed different restrictions.

While lambda cannot use non-final local variables, method reference has no such limitation.

Please check the details here: https://stackoverflow.com/questions/33052917/why-can-method-reference-use-non-final-variables

Hello everyone, I have tried and executed a program using method references but got confused in understanding effectively final variable in java in the following code :



If str is not effectively final, how does the program compiled and ran with output.

Tim Holloway wrote:An Interface is a contract. If a class implements an Interface, then it has promised that it will have implemented all of the methods defined in the Interface.

That's useful for a number of reason, including plug-replaceable components. And in particular test components.

If you have an interface definition you can construct a dummy or mock class that implements the indicated methods but does not have to actually do all the work that the "real" class does. That means that you can test your team's code without having to wait for the other team to deliver the "real" class.

Note that I distinguish between a "dummy" class and a "mock" class. In this context, a dummy class is simply a class that you implement yourself to test with. A Mock class is usually controlled by a mocking framework. Given a choice, I prefer dummy classes, but a mocked class can often be used in an environment where you need to pretend to connect to complex infrastructure and a dummy class can't be used.



Agreed. Let me frame and example on that. Correct me if i am going wrong

Ex:
public class House{};
public class RedHouse extends House{}
public class BlueHouse extends House{}

public interface Student{

House getHouse(List<House> houses, String studentLastName);

}

dummy class :

public class StudentImpl imlements Student{

List<Houses> houses = new ArrayList<>();
houses.add("RedHouse");
houses.add("BlueHouse");

@Override
House getHouse(houses, "lastName"){
return houses.get(0);
}

}

My team can use this  dummy class for testing and can write about House, RedHouse, BlueHouse etc.,

The other team can write the exact logic for getHouse with students last name and the houses list for a school. The other team will write the implementation of StudentImpl with business rules

Thus both teams can be engaged with interface as centric.






2 years ago
Hi Team,

I was just going through the Java 1.8 OCP book by Jeanne and Scott and there they mentioned about mock interface so that two different teams can do programming and join their code later.

I am not clear about the example quoted in the book , could any one please help me with few different and easily understandable examples.

Best Regards,

Swapna Kori
2 years ago
Hi All,

I am really confused in applying lambda map function where as the code which i am reading has got the result.



What i am doing wrong ? Please guide me .

Thanks & Regards,

Swapna.
4 years ago
Hi, I am working on few examples on Threads and i do see that Thread class has an Functional interface inside it.

I have seen an example in an udemy course like:



Could any one please exaplain the advantage of functional interface in a class.

Stephan van Hulst wrote:On a tangent: In general you don't need to worry about the A parameter. You only need to care about it if you implement your own Collector.


Thank you Stephan.
Thank you very much Tim. I got the answer now.

Tim Holloway wrote:Try this with 1:59 instead of 2:00. You might find it interesting. Indeed, try 1:59:59

Campbell Ritchie wrote:But Comparator is a functional interface.


Got it Campbell. Thank you very much.
But I have used BiFunction above. Comparator is not a Bifunction right.

Campbell Ritchie wrote:But Comparator is a functional interface.

Campbell Ritchie wrote:Have you seen the documentation for Collections#sort()?


Yes Campbell, it takes the second argument as Comparator but not function. So confused at this part.

Thanks & Regards,

Swapna

Stephan van Hulst wrote:You need to tell us what part of the explanation is not clear to you, and explain to us why you think it is 0.



Stephan, the lines of codes are as follows with my explanation . Correct me if i am wrong

LocalDateTime ld1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0); // This line of code is having a time of 2 AM so as per DST savings, it should become 1 AM
ZonedDateTime zd1 = ZonedDateTime.of(ld1, ZoneId.of("US/Eastern"));
LocalDateTime ld2 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0);// There wont be any change of time as the time is still 1 AM and time changes after 2 AM
ZonedDateTime zd2 = ZonedDateTime.of(ld2, ZoneId.of("US/Eastern"));// As both the times are 1 AM , the result is zero.

Thanks & Regards,

Swapna.
Hi All,

I am practising questions from both enthuware and whizlab and i have got struck in understanding how does sort method takes function as 2nd argument.



Question is how function as 2nd argument to sort method.

Thanks & Regards,

Swapna.