• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

The public type conflicts must be defined in its own file

 
Ranch Hand
Posts: 118
Android Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was the error message that shows for Conflicts

The issue here is

i wanted to check out how both

java.util.Date and java.sql.Date can be used in a code

i had two ways of doing it as per my knowledge that being

import java.util.Date

public class conflicts
{

Date date;

java.sql.Date sqlDate;

}

or

public class conflicts

{

java.util.Date date;
java.sql.Date sqlDate;

}

i get an error under conflicts stating "The public type conflicts must be defined in its own file".

How to go about it.



 
Saloon Keeper
Posts: 14268
321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Public types need to be declared in a source file of the same name. If your class is named "conflicts", the source file should be named "conflicts.java". Note that you should always start type names with a capital letter.

By the way, you shouldn't use java.util.Date anymore. Instead, use java.time.LocalDateTime or java.time.Instant.
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:
By the way, you shouldn't use java.util.Date anymore. Instead, use java.time.LocalDateTime or java.time.Instant.


This is assuming you're one of the lucky folks that gets to use Java 8. If you are stuck on an older version of Java, like some of us, look at the Joda time libraries. They were the source and inspiration for the improved Date classes in Java 8.
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
guess i need to update from java 7 to 8 to use java.time

what is the practical way of explicitly using java.util.Date and java.sql.Date in a program without any conflicts, are 2 ways that i mentioned the only or is there any other way as well assuming the java version to be 7
 
Stephan van Hulst
Saloon Keeper
Posts: 14268
321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, if you want to use two classes with the same name in the same file, at least on of them needs to be fully qualified. If you really have to use both at the same time, you should always fully qualify both of them so there's no confusion which one you're using at any given moment.
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help Stephan / Kevin

 
You can thank my dental hygienist for my untimely aliveness. So tiny:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic