Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Array of StringBuilder verboten?

 
Ranch Hand
Posts: 574
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I sort of understand the thinking behind this thread I started but I have to admit, I'm lying.  I fail to see how the compiler can't fix this, nor how the run time engine can't find the problem.

Anywhoo, can I assume the reason I can't make an array of StringBuilders is the same issue?  Or do I need to google some more to figure out what I'm doing wrong?
 
Marshal
Posts: 3658
516
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jim Venolia wrote:... can I assume the reason I can't make an array of StringBuilders is the same issue?  Or do I need to google some more to figure out what I'm doing wrong?


Yes - it's possbile to have an array of StringBuilders.  Specifically what problems are you having?  Can you post some code that shows what you you are doing?
 
Jim Venolia
Ranch Hand
Posts: 574
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Second person to say it's Kosher, I'll google some more.  My problem?  Right here.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem in your previous question was that you were trying to create an array of a generic type, which does not work well in Java, because generics and arrays do not work well together for historic reasons.

The designers of the Java language early on made the decision that arrays should be covariant, which turned out to be incompatible with how generics should work when generics were introduced in Java 5, but at that moment it was too late to make arrays invariant - that would have caused a backward compatibility problem. The ugly solution was to make it not allowed to make an array of a generic type.

But StringBuilder is not a generic type, so this problem is not relevant to creating an array of StringBuilder objects.
 
Marshal
Posts: 74085
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the difference does come to 37. But why do you need StringBuilders in an array? How does it relate to that decryption exercise?
 
Jim Venolia
Ranch Hand
Posts: 574
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets say my key length is 3.  First StringBuilder will have data[0], data[3], data[5], etc.  Second will have data[1], data[4], etc.  Third has data[2], data[5], etc.

Then I can turn the StringBuilders into an array of byte[] and loop over everything.

I'm starting to think an array of byte[data.length][] might be a better choice.
 
Jim Venolia
Ranch Hand
Posts: 574
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ooopsasecond (n) - The amount of time between seeing a typo and pressing 'submit'.

The first array will have data[0], data[3], data[6], etc.
 
Campbell Ritchie
Marshal
Posts: 74085
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree: if you need a byte[] use a byte[].
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic