Q:

Not getting 'of' method for TopicName class using com.google.cloud.pubsub.v1

I am using GCP PubSub and using the TopicName class. I want to write the below code:
TopicName topicName = TopicName.of(projectId, topicId);

But I can't get the 'of'method.
Please can anyone suggest what I am doing wrong.

A:

I am summarising our discussion as an answer.
You are referring to the documentation, which explains how to publish a message in PubSub using Java and you got an error referent to the TopicName.of(projectId, topicId). Since this method is referenced in the documentation, its execution depends on adding the required Java dependencies. In order to do so, you have to follow the Quickstart and prepare your environment. Afterwards, you will be able to follow the Publishing messages to topics tutorial.

