Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:57:07+00:00 2026-05-26T21:57:07+00:00

I am used to python-style REPL testing of code on a shell and I

  • 0

I am used to python-style REPL testing of code on a shell and I am learning Java. I recently learnt that almost all Java code can be executed in a REPL manner via groovy. So far the groovy console has helped me quickly test my Java code snippets.

I am trying to run the following Java code in the groovy console (which I happened to get from another Stackoverflow question):

String md5(String s)
{
        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuffer hexString = new StringBuffer();
        for (int i=0; i<messageDigest.length; i++)
        hexString.append(Integer.toHexString(0xFF & messageDigest[i]));

        return hexString.toString();
}

String md5hash = md5("a test message");

When I try to execute this, I am getting the following error message:

Primitive type literal: byte cannot be used as a method name at line: 5 column: 13. File: ConsoleScript0 at line: 6, column: 13

I searched for the error message here on SO and elsewhere, but I couldn’t get any clues. It seems to be valid Java code, so why does groovy think that I’m trying to use “byte” as a method name?

I’m using Groovy Version: 1.8.4 JVM: 1.6.0_26

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:57:08+00:00Added an answer on May 26, 2026 at 9:57 pm

    I don’t know why it’s giving exactly that error message, but try the more idiomatic way of declaring the variable:

    byte[] messageDigest = digest.digest();
    

    (I’d also strongly recommend that you don’t use String.getBytes() without specifying a character encoding. I assume you don’t really want the result to be platform-specific.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I occasionally see the list slice syntax used in Python code like this: newList
The dis module can be effectively used to disassemble Python methods, functions and classes
Python works on multiple platforms and can be used for desktop and web applications,
In Python there is a really neat function called zip which can be used
Whitespace is signification in Python in that code blocks are defined by their indentation.
What are the current rules for writing python code that will pass cleanly through
With python-gdata 2.0.14, I used the following pieces of code to create and upload
I'm a somewhat advanced C++/Java Developer who recently became interested in Python and I
Are Java style camelCase names good practice in Python. I know Capilized names should
I used Python to generate a CSV file. But when I open it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.