Thursday, January 17, 2019

Why not List<String> listString = new ArrayList<String>(); 
You can assign an ArrayList<String> to a List<String> reference variable, but you can never assign an object with one generic type to an object with another generic type, no matter what inheritance there is.
Above code gives compile time Error "Type mismatch: cannot convert from ArrayList<String> to List<Object>".



Note:
Object o1=new String();  -> Possible (Upcasting and Automatic in Java)
Stringo1=new Object ();  -> Not Possible

Related Posts:

  • HashMap vs ConcurrentHashMap Difference between HashMap and ConcurrentHashMap: ConcurrentHashMap is thread-safe that is the code can be accessed by single thread at a time. while HashMap is not thread-safe HashMap can be synchronized by using sy… Read More
  • Fibonacci Series Write a Java Program to print Fibonacci  series up to 10        public class Fibonacci { public static void main(String[] args) { int num = 10;  … Read More
  • 2nd highest salary of an employee? MySQL: Sub queries in SQL are great tool for this kind of scenario, here we first select maximum salary and then another maximum excluding result of subquery mysql> SELECT max(salary) FROM Employee WHERE salary NOT IN (S… Read More
  • foreach() method in Java Java API provides foreach() method since jdk1.8v. This method traverses each element of the collection until all elements have been Processed by the method or an exception is raised. Exceptions thrown by the Operation are pa… Read More
  • Static Keyword Static is a keyword in Java, which is used for static blocks variables methods and  inner classes or nested classes A static member can be accessed directly with the class name with out creating an object.  Th… Read More

0 comments:

Post a Comment

Selenium Training in Realtime

Blog helps to a student or IT employee to develop or improve skills in Software Testing.

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts