英文:
How do I annotate on an interface in java?
问题
我正在尝试创建一个带有注解的接口,然而,当我尝试创建注解时,我收到了“不允许在此处使用注解”的消息。我不明白为什么会出现这个问题,因为我正在遵循一个做完全相同操作并且在教程中运行正常的教程。这可能看起来是一个愚蠢的问题,但我刚入门编程,尽管我已经尝试过研究为什么会出现这个问题,但没有找到任何能解答我问题的东西。所以有人能解释一下为什么我不能在我的接口中添加注解吗?
package com.myapp.groceryapp;
import retrofit2.http.Headers;
import retrofit2.http.Body;
import retrofit2.http.POST;
public interface APIService {
@Headers(
{
"Content-Type:application/json",
"Authorization:AAAAwg8PTZg:APA91bEY2M-
GHRhnKptu3VuNaRK3daxSdLf1S8p5ltF8wCvQ5ylGFmSXNCeXnTfymzN5VqWpucoYn8T6wq2ffR6i45sFRO2GE7"
}
)
@POST("fcm/send")
}
英文:
I am trying to create an interface with an annotation, however, when I try to create the annotation I receive Annotations are not allowed here
. I don't understand why I am receiving this as I am following a tutorial that does the exact same thing and it works in the tutorial. This may seem like a dumb question but I am new to programming & I have tried researching why I am receiving this problem but found nothing that answers my question. So can someone please explain to me why I cannot annotate in my interface?
package com.myapp.groceryapp;
import retrofit2.http.Headers;
import retrofit2.http.Body;
import retrofit2.http.POST;
public interface APIService {
@Headers(
{
"Content-Type:application/json",
"Authorization:AAAAwg8PTZg:APA91bEY2M-
GHRhnKptu3VuNaRK3daxSdLf1S8p5ltF8wCvQ5ylGFmSXNCeXnTfymzN5VqWpucoYn8T6wq2ffR6i45sFRO2GE7"
}
)
@POST ("fcm/send")
}
答案1
得分: 0
你应该在接口内部注释函数。例如:
@Headers(
{
"Content-Type:application/json",
"Authorization:AAAAwg8PTZg:APA91bEY2M-
GHRhnKptu3VuNaRK3daxSdLf1S8p5ltF8wCvQ5ylGFmSXNCeXnTfymzN5VqWpucoYn8T6wq2ffR6i45sFRO2GE7"
}
)
@POST ("fcm/send")
Call<playlist> func(@Body fooParam param);
英文:
You should annotate functions inside interfaces.
for instance:
@Headers(
{
"Content-Type:application/json",
"Authorization:AAAAwg8PTZg:APA91bEY2M-
GHRhnKptu3VuNaRK3daxSdLf1S8p5ltF8wCvQ5ylGFmSXNCeXnTfymzN5VqWpucoYn8T6wq2ffR6i45sFRO2GE7"
}
)
@POST ("fcm/send")
Call<playlist> func(@Body fooParam param);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论