包装整数

时间:2018-04-17 01:28:37

标签: java wrapper wrapping

我需要创建一个接受要包装的整数的构造函数。我目前有:

public class IntegerRateable implements Rateable {

    private Integer object;

    public IntegerRateable(Integer object) {
        this.object = new Integer(object);
    }

我不确定我的代码有什么问题。我的印象是这应该允许它被包裹。

2 个答案:

答案 0 :(得分:1)

如果你想要的是,你的<script src="https://unpkg.com/vue"></script> <div id="app"> <p v-html="$options.filters.json(message)"></p> <p :inner-html.prop="message | json"></p> <p v-html="jsonMethod(message)"></p> </div>类包含一个Integer作为成员变量,试试这个:

IntegerRateable

然后,只需将public class IntegerRateable implements Rateable { private Integer object; public IntegerRateable (int number) { this.object = number; } 对象实例化为:

IntegerRateable

答案 1 :(得分:0)

You may first want to check your braces, you're missing a closing brace #include <stdio.h> #include <signal.h> #include <errno.h> #include <stdlib.h> #include <time.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <assert.h> #include <sys/wait.h> /* 24h = 24 * 60 * 60*/ #define TIMER_FREQUENCY 86400 void timer_expired(int sig) { // use this handler } int main(void) { struct sigaction act; clockid_t clock_id; timer_t timer_id; struct sigevent clock_sig_event; struct itimerspec timer_value; int ret; /* Register new action for SIGUSR1 */ memset(&act, 0, sizeof(struct sigaction)); act.sa_handler = timer_expired; ret = sigaction(SIGUSR1, &act, NULL); assert(ret == 0); clock_id = CLOCK_MONOTONIC; memset(&clock_sig_event, 0, sizeof( struct sigevent)); clock_sig_event.sigev_notify = SIGEV_SIGNAL; clock_sig_event.sigev_signo = SIGUSR1; clock_sig_event.sigev_notify_attributes = NULL; /* Creating process interval timer */ ret = timer_create(clock_id, &clock_sig_event, &timer_id); assert(ret == 0); /* setitng timer interval values */ memset(&timer_value, 0, sizeof(struct itimerspec)); timer_value.it_interval.tv_sec = TIMER_FREQUENCY; timer_value.it_interval.tv_nsec = 0; /* setting timer initial expiration values*/ timer_value.it_value.tv_sec = TIMER_FREQUENCY; timer_value.it_value.tv_nsec = 0; /* Create timer */ ret = timer_settime(timer_id, 0, &timer_value, NULL); assert(ret == 0); /* Now we have a timer with following features: * It will expire after 24 hours and excute fucntion timer_expired * upon expiration */ /* * Do something here * * To test, sleep() for 5 sec and set timer expiry as 1 sec i.e. * TIMER_FREQUENCY as 1. * In this case first timer will expire after 1 sec and sleep will * come out, also timer_expired() will be executed. Later time will expire after every 1 sec. * * We can also use SIGEV_THREAD instead of SIGEV_SIGNAL in clock_sig_event.sigev_notify * while creating timer_id using timer_create().In that case we need to check for other parameter * as well. */ exit(EXIT_SUCCESS); } .

If that's not the problem, I'am assuming that the problem is in this line } . There is nothing wrong with this, it's just that it using the Integer constructor has been deprecated which you can find out more about here https://docs.oracle.com/javase/9/docs/api/java/lang/Integer.html#Integer-int-

So the preferred way of doing it would be to do this.object = new Integer(object);

EDIT: Although, I don't see a point in doing this since you can just do this.object = new Integer.valueOf(object);