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".
java constructor syntax-error
|
show 1 more comment
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".
java constructor syntax-error
5
That's a class declaration, not a constructor declaration. A constructor would bepublic P(GregorianCalendar date)
- within apublic 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
|
show 1 more comment
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".
java constructor syntax-error
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
java constructor syntax-error
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 bepublic P(GregorianCalendar date)
- within apublic 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
|
show 1 more comment
5
That's a class declaration, not a constructor declaration. A constructor would bepublic P(GregorianCalendar date)
- within apublic 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
|
show 1 more comment
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;
Correct and complete answer. Upvoted for using the modernLocalDate
instead of the complex, poorly designed and long outdatedCalendar
.
– Ole V.V.
Nov 11 at 17:26
add a comment |
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;
Correct and complete answer. Upvoted for using the modernLocalDate
instead of the complex, poorly designed and long outdatedCalendar
.
– Ole V.V.
Nov 11 at 17:26
add a comment |
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;
Correct and complete answer. Upvoted for using the modernLocalDate
instead of the complex, poorly designed and long outdatedCalendar
.
– Ole V.V.
Nov 11 at 17:26
add a comment |
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;
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;
answered Nov 11 at 16:28
k5_
3,60121221
3,60121221
Correct and complete answer. Upvoted for using the modernLocalDate
instead of the complex, poorly designed and long outdatedCalendar
.
– Ole V.V.
Nov 11 at 17:26
add a comment |
Correct and complete answer. Upvoted for using the modernLocalDate
instead of the complex, poorly designed and long outdatedCalendar
.
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
5
That's a class declaration, not a constructor declaration. A constructor would be
public P(GregorianCalendar date)
- within apublic 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