Why can't I use GregorianCalendar as an object type as a constructor parameter?









up vote
1
down vote

favorite












Why can't I use GregorianCalendar as an object type as a constructor parameter?



public class P(GregorianCalendar date){


Why can't I do this?



The error it give me is "syntax error on token "class", char expected".










share|improve this question



















  • 5




    That's a class declaration, not a constructor declaration. A constructor would be public P(GregorianCalendar date) - within a public class P ... class declaration.
    – Jon Skeet
    Nov 11 at 16:18






  • 1




    And you should really avoid using this obsolete, badly designed class. Use classes of the java.time package. And while you're at it, use a meanungful name for your own class.
    – JB Nizet
    Nov 11 at 16:20











  • @JBNizet I need a type that stores dates
    – user10610048
    Nov 11 at 16:22






  • 1




    And there are several ones in the java.time package, all much better designed than GregorianCalendar, and suitable for various use-cases.
    – JB Nizet
    Nov 11 at 16:23







  • 1




    @user10610048 Read Jon Skeet's comment, carefully. That is the answer to your problem. Once you fixed your problem, following Jon's advice (you literally just have to copy and paste code), then read my comments, carefully. Date is not part of the java.time package.
    – JB Nizet
    Nov 11 at 16:27














up vote
1
down vote

favorite












Why can't I use GregorianCalendar as an object type as a constructor parameter?



public class P(GregorianCalendar date){


Why can't I do this?



The error it give me is "syntax error on token "class", char expected".










share|improve this question



















  • 5




    That's a class declaration, not a constructor declaration. A constructor would be public P(GregorianCalendar date) - within a public class P ... class declaration.
    – Jon Skeet
    Nov 11 at 16:18






  • 1




    And you should really avoid using this obsolete, badly designed class. Use classes of the java.time package. And while you're at it, use a meanungful name for your own class.
    – JB Nizet
    Nov 11 at 16:20











  • @JBNizet I need a type that stores dates
    – user10610048
    Nov 11 at 16:22






  • 1




    And there are several ones in the java.time package, all much better designed than GregorianCalendar, and suitable for various use-cases.
    – JB Nizet
    Nov 11 at 16:23







  • 1




    @user10610048 Read Jon Skeet's comment, carefully. That is the answer to your problem. Once you fixed your problem, following Jon's advice (you literally just have to copy and paste code), then read my comments, carefully. Date is not part of the java.time package.
    – JB Nizet
    Nov 11 at 16:27












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Why can't I use GregorianCalendar as an object type as a constructor parameter?



public class P(GregorianCalendar date){


Why can't I do this?



The error it give me is "syntax error on token "class", char expected".










share|improve this question















Why can't I use GregorianCalendar as an object type as a constructor parameter?



public class P(GregorianCalendar date){


Why can't I do this?



The error it give me is "syntax error on token "class", char expected".







java constructor syntax-error






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 17:30









Ole V.V.

26.3k62651




26.3k62651










asked Nov 11 at 16:16









user10610048

676




676







  • 5




    That's a class declaration, not a constructor declaration. A constructor would be public P(GregorianCalendar date) - within a public class P ... class declaration.
    – Jon Skeet
    Nov 11 at 16:18






  • 1




    And you should really avoid using this obsolete, badly designed class. Use classes of the java.time package. And while you're at it, use a meanungful name for your own class.
    – JB Nizet
    Nov 11 at 16:20











  • @JBNizet I need a type that stores dates
    – user10610048
    Nov 11 at 16:22






  • 1




    And there are several ones in the java.time package, all much better designed than GregorianCalendar, and suitable for various use-cases.
    – JB Nizet
    Nov 11 at 16:23







  • 1




    @user10610048 Read Jon Skeet's comment, carefully. That is the answer to your problem. Once you fixed your problem, following Jon's advice (you literally just have to copy and paste code), then read my comments, carefully. Date is not part of the java.time package.
    – JB Nizet
    Nov 11 at 16:27












  • 5




    That's a class declaration, not a constructor declaration. A constructor would be public P(GregorianCalendar date) - within a public class P ... class declaration.
    – Jon Skeet
    Nov 11 at 16:18






  • 1




    And you should really avoid using this obsolete, badly designed class. Use classes of the java.time package. And while you're at it, use a meanungful name for your own class.
    – JB Nizet
    Nov 11 at 16:20











  • @JBNizet I need a type that stores dates
    – user10610048
    Nov 11 at 16:22






  • 1




    And there are several ones in the java.time package, all much better designed than GregorianCalendar, and suitable for various use-cases.
    – JB Nizet
    Nov 11 at 16:23







  • 1




    @user10610048 Read Jon Skeet's comment, carefully. That is the answer to your problem. Once you fixed your problem, following Jon's advice (you literally just have to copy and paste code), then read my comments, carefully. Date is not part of the java.time package.
    – JB Nizet
    Nov 11 at 16:27







5




5




That's a class declaration, not a constructor declaration. A constructor would be public P(GregorianCalendar date) - within a public class P ... class declaration.
– Jon Skeet
Nov 11 at 16:18




That's a class declaration, not a constructor declaration. A constructor would be public P(GregorianCalendar date) - within a public class P ... class declaration.
– Jon Skeet
Nov 11 at 16:18




1




1




And you should really avoid using this obsolete, badly designed class. Use classes of the java.time package. And while you're at it, use a meanungful name for your own class.
– JB Nizet
Nov 11 at 16:20





And you should really avoid using this obsolete, badly designed class. Use classes of the java.time package. And while you're at it, use a meanungful name for your own class.
– JB Nizet
Nov 11 at 16:20













@JBNizet I need a type that stores dates
– user10610048
Nov 11 at 16:22




@JBNizet I need a type that stores dates
– user10610048
Nov 11 at 16:22




1




1




And there are several ones in the java.time package, all much better designed than GregorianCalendar, and suitable for various use-cases.
– JB Nizet
Nov 11 at 16:23





And there are several ones in the java.time package, all much better designed than GregorianCalendar, and suitable for various use-cases.
– JB Nizet
Nov 11 at 16:23





1




1




@user10610048 Read Jon Skeet's comment, carefully. That is the answer to your problem. Once you fixed your problem, following Jon's advice (you literally just have to copy and paste code), then read my comments, carefully. Date is not part of the java.time package.
– JB Nizet
Nov 11 at 16:27




@user10610048 Read Jon Skeet's comment, carefully. That is the answer to your problem. Once you fixed your problem, following Jon's advice (you literally just have to copy and paste code), then read my comments, carefully. Date is not part of the java.time package.
– JB Nizet
Nov 11 at 16:27












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










As Jon Skeet mentioned in the comments. Here is how you create a class with construtor that has one parameter



import java.time.LocalDate;

public class P
private LocalDate date;
public P(LocalDate date)
this.date = date;







share|improve this answer




















  • Correct and complete answer. Upvoted for using the modern LocalDate instead of the complex, poorly designed and long outdated Calendar.
    – Ole V.V.
    Nov 11 at 17:26











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250656%2fwhy-cant-i-use-gregoriancalendar-as-an-object-type-as-a-constructor-parameter%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










As Jon Skeet mentioned in the comments. Here is how you create a class with construtor that has one parameter



import java.time.LocalDate;

public class P
private LocalDate date;
public P(LocalDate date)
this.date = date;







share|improve this answer




















  • Correct and complete answer. Upvoted for using the modern LocalDate instead of the complex, poorly designed and long outdated Calendar.
    – Ole V.V.
    Nov 11 at 17:26















up vote
2
down vote



accepted










As Jon Skeet mentioned in the comments. Here is how you create a class with construtor that has one parameter



import java.time.LocalDate;

public class P
private LocalDate date;
public P(LocalDate date)
this.date = date;







share|improve this answer




















  • Correct and complete answer. Upvoted for using the modern LocalDate instead of the complex, poorly designed and long outdated Calendar.
    – Ole V.V.
    Nov 11 at 17:26













up vote
2
down vote



accepted







up vote
2
down vote



accepted






As Jon Skeet mentioned in the comments. Here is how you create a class with construtor that has one parameter



import java.time.LocalDate;

public class P
private LocalDate date;
public P(LocalDate date)
this.date = date;







share|improve this answer












As Jon Skeet mentioned in the comments. Here is how you create a class with construtor that has one parameter



import java.time.LocalDate;

public class P
private LocalDate date;
public P(LocalDate date)
this.date = date;








share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 16:28









k5_

3,60121221




3,60121221











  • Correct and complete answer. Upvoted for using the modern LocalDate instead of the complex, poorly designed and long outdated Calendar.
    – Ole V.V.
    Nov 11 at 17:26

















  • Correct and complete answer. Upvoted for using the modern LocalDate instead of the complex, poorly designed and long outdated Calendar.
    – Ole V.V.
    Nov 11 at 17:26
















Correct and complete answer. Upvoted for using the modern LocalDate instead of the complex, poorly designed and long outdated Calendar.
– Ole V.V.
Nov 11 at 17:26





Correct and complete answer. Upvoted for using the modern LocalDate instead of the complex, poorly designed and long outdated Calendar.
– Ole V.V.
Nov 11 at 17:26


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250656%2fwhy-cant-i-use-gregoriancalendar-as-an-object-type-as-a-constructor-parameter%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto